Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow access to bytes::Bytes from protobuf::Chars #721

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions protobuf/src/chars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::borrow::Borrow;
use std::fmt;
use std::ops::Deref;
use std::str;
use std::convert::AsRef;

use bytes::Bytes;

Expand Down Expand Up @@ -81,6 +82,12 @@ impl Borrow<str> for Chars {
}
}

impl AsRef<Bytes> for Chars {
fn as_ref(&self) -> &Bytes {
&self.0
}
}

impl fmt::Display for Chars {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand Down
3 changes: 2 additions & 1 deletion protobuf/src/reflect/runtime_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use std::collections::HashMap;
use std::fmt;
use std::marker;
use std::ops::Deref;

Check warning on line 6 in protobuf/src/reflect/runtime_types.rs

View workflow job for this annotation

GitHub Actions / rustfmt check

unused import: `std::ops::Deref`

Check warning on line 6 in protobuf/src/reflect/runtime_types.rs

View workflow job for this annotation

GitHub Actions / linux stable (default features)

unused import: `std::ops::Deref`

Check warning on line 6 in protobuf/src/reflect/runtime_types.rs

View workflow job for this annotation

GitHub Actions / linux beta (default features)

unused import: `std::ops::Deref`

#[cfg(feature = "bytes")]
use bytes::Bytes;
Expand Down Expand Up @@ -738,7 +739,7 @@
}

fn as_ref(value: &Chars) -> ReflectValueRef {
ReflectValueRef::String(value.as_ref())
ReflectValueRef::String(<Chars as Deref>::deref(value))
}

fn is_non_zero(value: &Chars) -> bool {
Expand Down
Loading