Skip to content

Commit d37722b

Browse files
committed
Clean up Value convenience functions
Signed-off-by: Nathaniel McCallum <[email protected]>
1 parent 8e8f542 commit d37722b

File tree

1 file changed

+9
-26
lines changed

1 file changed

+9
-26
lines changed

ciborium/src/value/mod.rs

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ impl Value {
178178
/// let value = Value::Text(String::from("hello"));
179179
///
180180
/// // We can read the String
181-
/// assert_eq!(value.as_text().unwrap(), &String::from("hello"));
181+
/// assert_eq!(value.as_text().unwrap(), "hello");
182182
/// ```
183-
pub fn as_text(&self) -> Option<&String> {
183+
pub fn as_text(&self) -> Option<&str> {
184184
match *self {
185185
Value::Text(ref s) => Some(s),
186186
_ => None,
@@ -205,23 +205,6 @@ impl Value {
205205
}
206206
}
207207

208-
/// If the `Value` is a `Text`, returns the associated `String` as an `&str`. Returns None
209-
/// otherwise.
210-
///
211-
/// ```
212-
/// # use ciborium::value::Value;
213-
/// #
214-
/// let value = Value::Text(String::from("hello"));
215-
///
216-
/// assert_eq!(value.as_str().unwrap(), "hello");
217-
/// ```
218-
pub fn as_str(&self) -> Option<&str> {
219-
match *self {
220-
Value::Text(ref s) => Some(s.as_str()),
221-
_ => None,
222-
}
223-
}
224-
225208
/// Returns true if the `Value` is a `Bool`. Returns false otherwise.
226209
///
227210
/// ```
@@ -287,12 +270,12 @@ impl Value {
287270
/// let value = Value::Tag(61, Box::from(Value::Bytes(vec![104, 101, 108, 108, 111])));
288271
///
289272
/// let (tag, data) = value.as_tag().unwrap();
290-
/// assert_eq!(tag, &61);
273+
/// assert_eq!(tag, 61);
291274
/// assert_eq!(data, &Value::Bytes(vec![104, 101, 108, 108, 111]));
292275
/// ```
293-
pub fn as_tag(&self) -> Option<(&u64, &Value)> {
294-
match &*self {
295-
Value::Tag(ref tag, data) => Some((tag, data)),
276+
pub fn as_tag(&self) -> Option<(u64, &Value)> {
277+
match self {
278+
Value::Tag(tag, data) => Some((*tag, data)),
296279
_ => None,
297280
}
298281
}
@@ -310,9 +293,9 @@ impl Value {
310293
/// assert_eq!(tag, &61);
311294
/// assert_eq!(data, &Value::Bytes(vec![]));
312295
/// ```
313-
pub fn as_tag_mut(&mut self) -> Option<(&u64, &mut Value)> {
314-
match *self {
315-
Value::Tag(ref tag, ref mut data) => Some((tag, data.as_mut())),
296+
pub fn as_tag_mut(&mut self) -> Option<(&mut u64, &mut Value)> {
297+
match self {
298+
Value::Tag(tag, data) => Some((tag, data.as_mut())),
316299
_ => None,
317300
}
318301
}

0 commit comments

Comments
 (0)