Skip to content

Commit

Permalink
added suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
cramt committed Feb 9, 2023
1 parent 164154b commit 0d28c58
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ bytes-crate = ["bytes"]
[dependencies]
magnus-macros = { version = "0.4.0", path = "magnus-macros" }
rb-sys = { version = "0.9.56", default-features = false, features = ["bindgen-rbimpls", "bindgen-deprecated-types"] }
bytes = { version = "1.4.0", optional = true }
bytes = { version = "1", optional = true }

[dev-dependencies]
magnus = { path = ".", features = ["embed", "rb-sys-interop"] }
Expand Down
15 changes: 15 additions & 0 deletions src/r_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,7 @@ impl RString {
/// let s = RString::new("example");
/// assert_eq!(s.to_bytes(), Bytes::from("example"));
/// ```
#[cfg_attr(docsrs, doc(cfg(feature = "bytes-crate")))]
#[cfg(feature = "bytes-crate")]
pub fn to_bytes(self) -> bytes::Bytes {
let vec = unsafe { self.as_slice().to_vec() };
Expand Down Expand Up @@ -1536,6 +1537,20 @@ impl From<&str> for Value {
}
}

#[cfg(feature = "bytes-crate")]
impl From<bytes::Bytes> for Value {
fn from(val: bytes::Bytes) -> Self {
val.into_value()
}
}

#[cfg(feature = "bytes-crate")]
impl IntoValue for bytes::Bytes {
fn into_value_with(self, handle: &RubyHandle) -> Value {
handle.str_from_slice(self.as_ref()).into()
}
}

impl IntoValue for String {
fn into_value_with(self, handle: &RubyHandle) -> Value {
handle.str_new(self.as_str()).into()
Expand Down

0 comments on commit 0d28c58

Please sign in to comment.