Skip to main content

str

Macro str 

Source
macro_rules! str {
    ($x:expr) => { ... };
}
Expand description

Create a Value::Str from all things IntoStr (&str, String, &[u8], Vec<u8> etc.)`

Values will be borrowed or owned depending on the input type and pass by value/reference.

use bencode_minimal::*;
use std::borrow::Cow;

let v = str!("hello");
assert_eq!(v, Value::Str(Cow::Borrowed(b"hello")));

let v = str!("hello".to_string());
assert_eq!(v, Value::Str(Cow::Owned(b"hello".to_vec())));

let v = str!(b"hello");
assert_eq!(v, Value::Str(Cow::Borrowed(b"hello")));

let v = str!(b"world".to_vec());
assert_eq!(v, Value::Str(Cow::Owned(b"world".to_vec())));