Skip to content

Commit

Permalink
deprecate OwnedValue::from_value in favour of OwnedValue::collect (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
KodrAus authored Jan 23, 2019
1 parent c67d18d commit b12ad74
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
6 changes: 3 additions & 3 deletions benches/owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use test::{
#[bench]
fn collect_primitive(b: &mut Bencher) {
b.iter(|| {
let value = value::OwnedValue::from_value(1);
let value = value::OwnedValue::collect(1);

black_box(value);
})
Expand All @@ -23,7 +23,7 @@ fn collect_primitive(b: &mut Bencher) {
#[bench]
fn collect_primitive_string(b: &mut Bencher) {
b.iter(|| {
let value = value::OwnedValue::from_value("A string");
let value = value::OwnedValue::collect("A string");

black_box(value);
})
Expand Down Expand Up @@ -52,7 +52,7 @@ fn collect_complex(b: &mut Bencher) {
}

b.iter(|| {
let value = value::OwnedValue::from_value(Map);
let value = value::OwnedValue::collect(Map);

black_box(value);
});
Expand Down
2 changes: 1 addition & 1 deletion src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ mod std_support {
Collect a value into a sequence of tokens.
*/
pub fn tokens(v: impl Value) -> Vec<Token> {
OwnedValue::from_value(v)
OwnedValue::collect(v)
.tokens()
.unwrap()
.iter()
Expand Down
7 changes: 6 additions & 1 deletion src/value/owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl OwnedValue {
[`Value`]: struct.Value.html
*/
pub fn from_value(v: impl Value) -> Self {
pub fn collect(v: impl Value) -> Self {
// Try get a primitive first
// If the value is a simple primitive that can
// be represented in a single token then we can avoid
Expand All @@ -69,6 +69,11 @@ impl OwnedValue {
pub fn from_shared(v: impl Into<Arc<dyn Value + Send + Sync>>) -> Self {
OwnedValue(ValueInner::Shared(v.into()))
}

#[deprecated(since = "0.1.2", note = "use `collect` instead")]
pub fn from_value(v: impl Value) -> Self {
Self::collect(v)
}
}

enum ValueInner {
Expand Down

0 comments on commit b12ad74

Please sign in to comment.