Skip to content

Commit

Permalink
Adds conversion from byte literals to Bytes (#510)
Browse files Browse the repository at this point in the history
  • Loading branch information
popematt authored Apr 12, 2023
1 parent 3fa5844 commit 4f2eae6
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/element/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
/// let bytes: Bytes = "hello".into();
/// assert_eq!(&bytes, "hello".as_bytes());
/// ```
/// ```rust
/// use ion_rs::element::Bytes;
/// let bytes: Bytes = b"world".into();
/// assert_eq!(&bytes, b"world".as_slice());
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Bytes {
data: Vec<u8>,
Expand All @@ -35,6 +40,14 @@ impl From<&[u8]> for Bytes {
}
}

impl<const N: usize> From<&[u8; N]> for Bytes {
fn from(data: &[u8; N]) -> Self {
Bytes {
data: data.to_vec(),
}
}
}

impl From<&str> for Bytes {
fn from(text: &str) -> Self {
Bytes {
Expand Down

0 comments on commit 4f2eae6

Please sign in to comment.