pub type Fragment<'a> = Cow<'a, str>;
Expand description
A fragment of Text
.
This is just an alias to a string that may be either borrowed or owned.
Aliased Type§
enum Fragment<'a> {
Borrowed(&'a str),
Owned(String),
}
Variants§
Implementations
source§impl<B> Cow<'_, B>
impl<B> Cow<'_, B>
sourcepub const fn is_borrowed(&self) -> bool
🔬This is a nightly-only experimental API. (cow_is_borrowed
)
pub const fn is_borrowed(&self) -> bool
cow_is_borrowed
)Returns true if the data is borrowed, i.e. if to_mut
would require additional work.
§Examples
#![feature(cow_is_borrowed)]
use std::borrow::Cow;
let cow = Cow::Borrowed("moo");
assert!(cow.is_borrowed());
let bull: Cow<'_, str> = Cow::Owned("...moo?".to_string());
assert!(!bull.is_borrowed());
sourcepub const fn is_owned(&self) -> bool
🔬This is a nightly-only experimental API. (cow_is_borrowed
)
pub const fn is_owned(&self) -> bool
cow_is_borrowed
)Returns true if the data is owned, i.e. if to_mut
would be a no-op.
§Examples
#![feature(cow_is_borrowed)]
use std::borrow::Cow;
let cow: Cow<'_, str> = Cow::Owned("moo".to_string());
assert!(cow.is_owned());
let bull = Cow::Borrowed("...moo?");
assert!(!bull.is_owned());
1.0.0 · sourcepub fn to_mut(&mut self) -> &mut <B as ToOwned>::Owned
pub fn to_mut(&mut self) -> &mut <B as ToOwned>::Owned
Acquires a mutable reference to the owned form of the data.
Clones the data if it is not already owned.
§Examples
use std::borrow::Cow;
let mut cow = Cow::Borrowed("foo");
cow.to_mut().make_ascii_uppercase();
assert_eq!(
cow,
Cow::Owned(String::from("FOO")) as Cow<'_, str>
);
1.0.0 · sourcepub fn into_owned(self) -> <B as ToOwned>::Owned
pub fn into_owned(self) -> <B as ToOwned>::Owned
Extracts the owned data.
Clones the data if it is not already owned.
§Examples
Calling into_owned
on a Cow::Borrowed
returns a clone of the borrowed data:
use std::borrow::Cow;
let s = "Hello world!";
let cow = Cow::Borrowed(s);
assert_eq!(
cow.into_owned(),
String::from(s)
);
Calling into_owned
on a Cow::Owned
returns the owned data. The data is moved out of the
Cow
without being cloned.
use std::borrow::Cow;
let s = "Hello world!";
let cow: Cow<'_, str> = Cow::Owned(String::from(s));
assert_eq!(
cow.into_owned(),
String::from(s)
);
Trait Implementations
1.14.0 · source§impl<'a> AddAssign<&'a str> for Cow<'a, str>
impl<'a> AddAssign<&'a str> for Cow<'a, str>
source§fn add_assign(&mut self, rhs: &'a str)
fn add_assign(&mut self, rhs: &'a str)
Performs the
+=
operation. Read moresource§impl<'a> Arg for Cow<'a, str>
impl<'a> Arg for Cow<'a, str>
source§fn to_string_lossy(&self) -> Cow<'_, str>
fn to_string_lossy(&self) -> Cow<'_, str>
Returns a potentially-lossy rendering of this string as a
Cow<'_, str>
.source§fn as_cow_c_str(&self) -> Result<Cow<'_, CStr>, Errno>
fn as_cow_c_str(&self) -> Result<Cow<'_, CStr>, Errno>
Returns a view of this string as a maybe-owned
CStr
.source§impl<T> AsRawXcbConnection for Cow<'_, T>
impl<T> AsRawXcbConnection for Cow<'_, T>
source§fn as_raw_xcb_connection(&self) -> *mut xcb_connection_t
fn as_raw_xcb_connection(&self) -> *mut xcb_connection_t
Get a raw xcb connection pointer from this object.
source§impl<C> Connection for Cow<'_, C>
impl<C> Connection for Cow<'_, C>
source§fn wait_for_event(&self) -> Result<Event, ConnectionError>
fn wait_for_event(&self) -> Result<Event, ConnectionError>
Wait for a new event from the X11 server.
source§fn wait_for_raw_event(
&self,
) -> Result<<Cow<'_, C> as RequestConnection>::Buf, ConnectionError>
fn wait_for_raw_event( &self, ) -> Result<<Cow<'_, C> as RequestConnection>::Buf, ConnectionError>
Wait for a new raw/unparsed event from the X11 server.
source§fn wait_for_event_with_sequence(&self) -> Result<(Event, u64), ConnectionError>
fn wait_for_event_with_sequence(&self) -> Result<(Event, u64), ConnectionError>
Wait for a new event from the X11 server.
source§fn wait_for_raw_event_with_sequence(
&self,
) -> Result<(<Cow<'_, C> as RequestConnection>::Buf, u64), ConnectionError>
fn wait_for_raw_event_with_sequence( &self, ) -> Result<(<Cow<'_, C> as RequestConnection>::Buf, u64), ConnectionError>
Wait for a new raw/unparsed event from the X11 server.
source§fn poll_for_event(&self) -> Result<Option<Event>, ConnectionError>
fn poll_for_event(&self) -> Result<Option<Event>, ConnectionError>
Poll for a new event from the X11 server.
source§fn poll_for_raw_event(
&self,
) -> Result<Option<<Cow<'_, C> as RequestConnection>::Buf>, ConnectionError>
fn poll_for_raw_event( &self, ) -> Result<Option<<Cow<'_, C> as RequestConnection>::Buf>, ConnectionError>
Poll for a new raw/unparsed event from the X11 server.
source§fn poll_for_event_with_sequence(
&self,
) -> Result<Option<(Event, u64)>, ConnectionError>
fn poll_for_event_with_sequence( &self, ) -> Result<Option<(Event, u64)>, ConnectionError>
Poll for a new event from the X11 server.
source§fn poll_for_raw_event_with_sequence(
&self,
) -> Result<Option<(<Cow<'_, C> as RequestConnection>::Buf, u64)>, ConnectionError>
fn poll_for_raw_event_with_sequence( &self, ) -> Result<Option<(<Cow<'_, C> as RequestConnection>::Buf, u64)>, ConnectionError>
Poll for a new unparsed/raw event from the X11 server.
source§fn flush(&self) -> Result<(), ConnectionError>
fn flush(&self) -> Result<(), ConnectionError>
Send all pending requests to the server. Read more
source§fn generate_id(&self) -> Result<u32, ReplyOrIdError>
fn generate_id(&self) -> Result<u32, ReplyOrIdError>
Generate a new X11 identifier. Read more
source§impl<'de, 'a, T> Deserialize<'de> for Cow<'a, T>
impl<'de, 'a, T> Deserialize<'de> for Cow<'a, T>
source§fn deserialize<D>(
deserializer: D,
) -> Result<Cow<'a, T>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<Cow<'a, T>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl<T> EncodeAsVarULE<T> for Cow<'_, T>
impl<T> EncodeAsVarULE<T> for Cow<'_, T>
source§fn encode_var_ule_as_slices<R>(&self, cb: impl FnOnce(&[&[u8]]) -> R) -> R
fn encode_var_ule_as_slices<R>(&self, cb: impl FnOnce(&[&[u8]]) -> R) -> R
Calls
cb
with a piecewise list of byte slices that when concatenated
produce the memory pattern of the corresponding instance of T
. Read moresource§fn encode_var_ule_len(&self) -> usize
fn encode_var_ule_len(&self) -> usize
Return the length, in bytes, of the corresponding
VarULE
typesource§fn encode_var_ule_write(&self, dst: &mut [u8])
fn encode_var_ule_write(&self, dst: &mut [u8])
Write the corresponding
VarULE
type to the dst
buffer. dst
should
be the size of Self::encode_var_ule_len()
source§impl<'de, 'a, E> IntoDeserializer<'de, E> for Cow<'a, str>where
E: Error,
impl<'de, 'a, E> IntoDeserializer<'de, E> for Cow<'a, str>where
E: Error,
source§type Deserializer = CowStrDeserializer<'a, E>
type Deserializer = CowStrDeserializer<'a, E>
The type of the deserializer being converted into.
source§fn into_deserializer(self) -> CowStrDeserializer<'a, E>
fn into_deserializer(self) -> CowStrDeserializer<'a, E>
Convert this value into a deserializer.
source§impl<'a> IntoFragment<'a> for Cow<'a, str>
impl<'a> IntoFragment<'a> for Cow<'a, str>
1.0.0 · source§impl<B> Ord for Cow<'_, B>
impl<B> Ord for Cow<'_, B>
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.0.0 · source§impl<'a, B> PartialOrd for Cow<'a, B>
impl<'a, B> PartialOrd for Cow<'a, B>
source§impl<C> RequestConnection for Cow<'_, C>
impl<C> RequestConnection for Cow<'_, C>
source§type Buf = <C as RequestConnection>::Buf
type Buf = <C as RequestConnection>::Buf
Type used as buffer to store raw replies or events before
they are parsed.
source§fn send_request_with_reply<R>(
&self,
bufs: &[IoSlice<'_>],
fds: Vec<OwnedFd>,
) -> Result<Cookie<'_, Cow<'_, C>, R>, ConnectionError>where
R: TryParse,
fn send_request_with_reply<R>(
&self,
bufs: &[IoSlice<'_>],
fds: Vec<OwnedFd>,
) -> Result<Cookie<'_, Cow<'_, C>, R>, ConnectionError>where
R: TryParse,
Send a request with a reply to the server. Read more
source§fn send_trait_request_with_reply<R>(
&self,
request: R,
) -> Result<Cookie<'_, Cow<'_, C>, <R as ReplyRequest>::Reply>, ConnectionError>where
R: ReplyRequest,
fn send_trait_request_with_reply<R>(
&self,
request: R,
) -> Result<Cookie<'_, Cow<'_, C>, <R as ReplyRequest>::Reply>, ConnectionError>where
R: ReplyRequest,
Send a request with a reply to the server. Read more
source§fn send_request_with_reply_with_fds<R>(
&self,
bufs: &[IoSlice<'_>],
fds: Vec<OwnedFd>,
) -> Result<CookieWithFds<'_, Cow<'_, C>, R>, ConnectionError>where
R: TryParseFd,
fn send_request_with_reply_with_fds<R>(
&self,
bufs: &[IoSlice<'_>],
fds: Vec<OwnedFd>,
) -> Result<CookieWithFds<'_, Cow<'_, C>, R>, ConnectionError>where
R: TryParseFd,
Send a request with a reply containing file descriptors to the server. Read more
source§fn send_trait_request_with_reply_with_fds<R>(
&self,
request: R,
) -> Result<CookieWithFds<'_, Cow<'_, C>, <R as ReplyFDsRequest>::Reply>, ConnectionError>where
R: ReplyFDsRequest,
fn send_trait_request_with_reply_with_fds<R>(
&self,
request: R,
) -> Result<CookieWithFds<'_, Cow<'_, C>, <R as ReplyFDsRequest>::Reply>, ConnectionError>where
R: ReplyFDsRequest,
Send a request with a reply containing file descriptors to the server. Read more
source§fn send_request_without_reply(
&self,
bufs: &[IoSlice<'_>],
fds: Vec<OwnedFd>,
) -> Result<VoidCookie<'_, Cow<'_, C>>, ConnectionError>
fn send_request_without_reply( &self, bufs: &[IoSlice<'_>], fds: Vec<OwnedFd>, ) -> Result<VoidCookie<'_, Cow<'_, C>>, ConnectionError>
Send a request without a reply to the server. Read more
source§fn send_trait_request_without_reply<R>(
&self,
request: R,
) -> Result<VoidCookie<'_, Cow<'_, C>>, ConnectionError>where
R: VoidRequest,
fn send_trait_request_without_reply<R>(
&self,
request: R,
) -> Result<VoidCookie<'_, Cow<'_, C>>, ConnectionError>where
R: VoidRequest,
Send a request without a reply to the server. Read more
source§fn discard_reply(&self, sequence: u64, kind: RequestKind, mode: DiscardMode)
fn discard_reply(&self, sequence: u64, kind: RequestKind, mode: DiscardMode)
A reply to an error should be discarded. Read more
source§fn prefetch_extension_information(
&self,
extension_name: &'static str,
) -> Result<(), ConnectionError>
fn prefetch_extension_information( &self, extension_name: &'static str, ) -> Result<(), ConnectionError>
Prefetches information about an extension. Read more
source§fn extension_information(
&self,
extension_name: &'static str,
) -> Result<Option<ExtensionInformation>, ConnectionError>
fn extension_information( &self, extension_name: &'static str, ) -> Result<Option<ExtensionInformation>, ConnectionError>
Get information about an extension. Read more
source§fn wait_for_reply_or_error(
&self,
sequence: u64,
) -> Result<<Cow<'_, C> as RequestConnection>::Buf, ReplyError>
fn wait_for_reply_or_error( &self, sequence: u64, ) -> Result<<Cow<'_, C> as RequestConnection>::Buf, ReplyError>
Wait for the reply to a request. Read more
source§fn wait_for_reply_or_raw_error(
&self,
sequence: u64,
) -> Result<ReplyOrError<<Cow<'_, C> as RequestConnection>::Buf>, ConnectionError>
fn wait_for_reply_or_raw_error( &self, sequence: u64, ) -> Result<ReplyOrError<<Cow<'_, C> as RequestConnection>::Buf>, ConnectionError>
Wait for the reply to a request. Read more
source§fn wait_for_reply(
&self,
sequence: u64,
) -> Result<Option<<Cow<'_, C> as RequestConnection>::Buf>, ConnectionError>
fn wait_for_reply( &self, sequence: u64, ) -> Result<Option<<Cow<'_, C> as RequestConnection>::Buf>, ConnectionError>
Wait for the reply to a request. Read more
source§fn wait_for_reply_with_fds(
&self,
sequence: u64,
) -> Result<(<Cow<'_, C> as RequestConnection>::Buf, Vec<OwnedFd>), ReplyError>
fn wait_for_reply_with_fds( &self, sequence: u64, ) -> Result<(<Cow<'_, C> as RequestConnection>::Buf, Vec<OwnedFd>), ReplyError>
Wait for the reply to a request that has FDs. Read more
source§fn wait_for_reply_with_fds_raw(
&self,
sequence: u64,
) -> Result<ReplyOrError<(<Cow<'_, C> as RequestConnection>::Buf, Vec<OwnedFd>), <Cow<'_, C> as RequestConnection>::Buf>, ConnectionError>
fn wait_for_reply_with_fds_raw( &self, sequence: u64, ) -> Result<ReplyOrError<(<Cow<'_, C> as RequestConnection>::Buf, Vec<OwnedFd>), <Cow<'_, C> as RequestConnection>::Buf>, ConnectionError>
Wait for the reply to a request that has FDs. Read more
source§fn check_for_error(&self, sequence: u64) -> Result<(), ReplyError>
fn check_for_error(&self, sequence: u64) -> Result<(), ReplyError>
Check whether a request that does not have a reply caused an X11 error. Read more
source§fn check_for_raw_error(
&self,
sequence: u64,
) -> Result<Option<<Cow<'_, C> as RequestConnection>::Buf>, ConnectionError>
fn check_for_raw_error( &self, sequence: u64, ) -> Result<Option<<Cow<'_, C> as RequestConnection>::Buf>, ConnectionError>
Check whether a request that does not have a reply caused an X11 error. Read more
source§fn prefetch_maximum_request_bytes(&self)
fn prefetch_maximum_request_bytes(&self)
Prefetches the maximum request length. Read more
source§fn maximum_request_bytes(&self) -> usize
fn maximum_request_bytes(&self) -> usize
The maximum number of bytes that the X11 server accepts in a request.
source§fn parse_error(&self, error: &[u8]) -> Result<X11Error, ParseError>
fn parse_error(&self, error: &[u8]) -> Result<X11Error, ParseError>
Parse a generic error.
source§fn parse_event(&self, event: &[u8]) -> Result<Event, ParseError>
fn parse_event(&self, event: &[u8]) -> Result<Event, ParseError>
Parse a generic event.
source§impl<'a, T> Serialize for Cow<'a, T>
impl<'a, T> Serialize for Cow<'a, T>
source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Serialize this value into the given Serde serializer. Read more
source§impl<'a, T> Writeable for Cow<'a, T>
impl<'a, T> Writeable for Cow<'a, T>
source§fn write_to<W>(&self, sink: &mut W) -> Result<(), Error>
fn write_to<W>(&self, sink: &mut W) -> Result<(), Error>
Writes a string to the given sink. Errors from the sink are bubbled up.
The default implementation delegates to
write_to_parts
, and discards any
Part
annotations.source§fn write_to_parts<W>(&self, sink: &mut W) -> Result<(), Error>where
W: PartsWrite + ?Sized,
fn write_to_parts<W>(&self, sink: &mut W) -> Result<(), Error>where
W: PartsWrite + ?Sized,
Write bytes and
Part
annotations to the given sink. Errors from the
sink are bubbled up. The default implementation delegates to write_to
,
and doesn’t produce any Part
annotations.source§fn writeable_length_hint(&self) -> LengthHint
fn writeable_length_hint(&self) -> LengthHint
Returns a hint for the number of UTF-8 bytes that will be written to the sink. Read more
source§impl<'a, T> Yokeable<'a> for Cow<'static, T>
impl<'a, T> Yokeable<'a> for Cow<'static, T>
source§type Output = Cow<'a, T>
type Output = Cow<'a, T>
This type MUST be
Self
with the 'static
replaced with 'a
, i.e. Self<'a>