rustc_error_messages

Type Alias FluentId

Source
pub(crate) type FluentId = Cow<'static, str>;
Expand description

Identifier for the Fluent message/attribute corresponding to a diagnostic message.

Aliased Type§

enum FluentId {
    Borrowed(&'static str),
    Owned(String),
}

Variants§

§

Borrowed(&'static str)

Borrowed data.

§

Owned(String)

Owned data.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 24 bytes

Size for each variant:

  • Borrowed: 24 bytes
  • Owned: 24 bytes

Implementations

Source§

impl<B> Cow<'_, B>
where B: ToOwned + ?Sized,

Source

pub const fn is_borrowed(&self) -> bool

🔬This is a nightly-only experimental API. (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());
Source

pub const fn is_owned(&self) -> bool

🔬This is a nightly-only experimental API. (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 · Source

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 · Source

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> Add<&'a str> for Cow<'a, str>

Source§

type Output = Cow<'a, str>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &'a str) -> Cow<'a, str>

Performs the + operation. Read more
1.14.0 · Source§

impl<'a> Add for Cow<'a, str>

Source§

type Output = Cow<'a, str>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Cow<'a, str>) -> Cow<'a, str>

Performs the + operation. Read more
1.14.0 · Source§

impl<'a> AddAssign<&'a str> for Cow<'a, str>

Source§

fn add_assign(&mut self, rhs: &'a str)

Performs the += operation. Read more
1.14.0 · Source§

impl<'a> AddAssign for Cow<'a, str>

Source§

fn add_assign(&mut self, rhs: Cow<'a, str>)

Performs the += operation. Read more
Source§

impl<'a> Arg for Cow<'a, str>

Source§

fn as_str(&self) -> Result<&str, Errno>

Returns a view of this string as a string slice.
Source§

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>

Returns a view of this string as a maybe-owned CStr.
Source§

fn into_c_str<'b>(self) -> Result<Cow<'b, CStr>, Errno>
where Cow<'a, str>: 'b,

Consumes self and returns a view of this string as a maybe-owned CStr.
Source§

fn into_with_c_str<T, F>(self, f: F) -> Result<T, Errno>
where Cow<'a, str>: Sized, F: FnOnce(&CStr) -> Result<T, Errno>,

Runs a closure with self passed in as a &CStr.
1.0.0 · Source§

impl<T> AsRef<T> for Cow<'_, T>
where T: ToOwned + ?Sized,

Source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
1.0.0 · Source§

impl<'a, B> Borrow<B> for Cow<'a, B>
where B: ToOwned + ?Sized,

Source§

fn borrow(&self) -> &B

Immutably borrows from an owned value. Read more
1.0.0 · Source§

impl<B> Clone for Cow<'_, B>
where B: ToOwned + ?Sized,

Source§

fn clone(&self) -> Cow<'_, B>

Returns a copy of the value. Read more
Source§

fn clone_from(&mut self, source: &Cow<'_, B>)

Performs copy-assignment from source. Read more
1.0.0 · Source§

impl<B> Debug for Cow<'_, B>
where B: Debug + ToOwned + ?Sized, <B as ToOwned>::Owned: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<D> Decodable<D> for Cow<'_, str>
where D: Decoder,

Source§

fn decode(d: &mut D) -> Cow<'static, str>

1.11.0 · Source§

impl<B> Default for Cow<'_, B>
where B: ToOwned + ?Sized, <B as ToOwned>::Owned: Default,

Source§

fn default() -> Cow<'_, B>

Creates an owned Cow<’a, B> with the default value for the contained owned value.

1.0.0 · Source§

impl<B> Deref for Cow<'_, B>
where B: ToOwned + ?Sized, <B as ToOwned>::Owned: Borrow<B>,

Source§

type Target = B

The resulting type after dereferencing.
Source§

fn deref(&self) -> &B

Dereferences the value.
1.0.0 · Source§

impl<B> Display for Cow<'_, B>
where B: Display + ToOwned + ?Sized, <B as ToOwned>::Owned: Display,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<S> Encodable<S> for Cow<'_, str>
where S: Encoder,

Source§

fn encode(&self, s: &mut S)

Source§

impl<T> EncodeAsVarULE<T> for Cow<'_, T>
where T: VarULE + ToOwned + ?Sized,

Source§

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 more
Source§

fn encode_var_ule_len(&self) -> usize

Return the length, in bytes, of the corresponding VarULE type
Source§

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()
1.28.0 · Source§

impl<'a> From<&'a String> for Cow<'a, str>

Source§

fn from(s: &'a String) -> Cow<'a, str>

Converts a String reference into a Borrowed variant. No heap allocation is performed, and the string is not copied.

§Example
let s = "eggplant".to_string();
assert_eq!(Cow::from(&s), Cow::Borrowed("eggplant"));
1.0.0 · Source§

impl<'a> From<&'a str> for Cow<'a, str>

Source§

fn from(s: &'a str) -> Cow<'a, str>

Converts a string slice into a Borrowed variant. No heap allocation is performed, and the string is not copied.

§Example
assert_eq!(Cow::from("eggplant"), Cow::Borrowed("eggplant"));
1.0.0 · Source§

impl<'a> From<String> for Cow<'a, str>

Source§

fn from(s: String) -> Cow<'a, str>

Converts a String into an Owned variant. No heap allocation is performed, and the string is not copied.

§Example
let s = "eggplant".to_string();
let s2 = "eggplant".to_string();
assert_eq!(Cow::from(s), Cow::<'static, str>::Owned(s2));
1.12.0 · Source§

impl<'a, 'b> FromIterator<&'b str> for Cow<'a, str>

Source§

fn from_iter<I>(it: I) -> Cow<'a, str>
where I: IntoIterator<Item = &'b str>,

Creates a value from an iterator. Read more
1.12.0 · Source§

impl<'a> FromIterator<String> for Cow<'a, str>

Source§

fn from_iter<I>(it: I) -> Cow<'a, str>
where I: IntoIterator<Item = String>,

Creates a value from an iterator. Read more
1.12.0 · Source§

impl<'a> FromIterator<char> for Cow<'a, str>

Source§

fn from_iter<I>(it: I) -> Cow<'a, str>
where I: IntoIterator<Item = char>,

Creates a value from an iterator. Read more
Source§

impl<'a, C, T> FromParallelIterator<T> for Cow<'a, C>
where C: ToOwned + ?Sized, <C as ToOwned>::Owned: FromParallelIterator<T>, T: Send,

Collects an arbitrary Cow collection.

Note, the standard library only has FromIterator for Cow<'a, str> and Cow<'a, [T]>, because no one thought to add a blanket implementation before it was stabilized.

Source§

fn from_par_iter<I>(par_iter: I) -> Cow<'a, C>
where I: IntoParallelIterator<Item = T>,

Creates an instance of the collection from the parallel iterator par_iter. Read more
1.0.0 · Source§

impl<B> Hash for Cow<'_, B>
where B: Hash + ToOwned + ?Sized,

Source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
1.0.0 · Source§

impl<B> Ord for Cow<'_, B>
where B: Ord + ToOwned + ?Sized,

Source§

fn cmp(&self, other: &Cow<'_, B>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
1.0.0 · Source§

impl<'a, 'b> PartialEq<&'b str> for Cow<'a, str>

Source§

fn eq(&self, other: &&'b str) -> bool

Tests for self and other values to be equal, and is used by ==.
Source§

fn ne(&self, other: &&'b str) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
1.0.0 · Source§

impl<'a, 'b, B, C> PartialEq<Cow<'b, C>> for Cow<'a, B>
where B: PartialEq<C> + ToOwned + ?Sized, C: ToOwned + ?Sized,

Source§

fn eq(&self, other: &Cow<'b, C>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
1.0.0 · Source§

impl<'a, 'b> PartialEq<String> for Cow<'a, str>

Source§

fn eq(&self, other: &String) -> bool

Tests for self and other values to be equal, and is used by ==.
Source§

fn ne(&self, other: &String) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
1.0.0 · Source§

impl<'a, 'b> PartialEq<str> for Cow<'a, str>

Source§

fn eq(&self, other: &str) -> bool

Tests for self and other values to be equal, and is used by ==.
Source§

fn ne(&self, other: &str) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
1.0.0 · Source§

impl<'a, B> PartialOrd for Cow<'a, B>
where B: PartialOrd + ToOwned + ?Sized,

Source§

fn partial_cmp(&self, other: &Cow<'a, B>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'a, T> Writeable for Cow<'a, T>
where T: Writeable + ToOwned + ?Sized,

Source§

fn write_to<W>(&self, sink: &mut W) -> Result<(), Error>
where W: Write + ?Sized,

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,

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

Returns a hint for the number of UTF-8 bytes that will be written to the sink. Read more
Source§

fn write_to_string(&self) -> Cow<'_, str>

Creates a new String with the data from this Writeable. Like ToString, but smaller and faster. Read more
Source§

fn writeable_cmp_bytes(&self, other: &[u8]) -> Ordering

Compares the contents of this Writeable to the given bytes without allocating a String to hold the Writeable contents. Read more
Source§

impl<'a, T> Yokeable<'a> for Cow<'static, T>
where T: 'static + ToOwned + ?Sized, <T as ToOwned>::Owned: Sized,

Source§

type Output = Cow<'a, T>

This type MUST be Self with the 'static replaced with 'a, i.e. Self<'a>
Source§

fn transform(&'a self) -> &'a Cow<'a, T>

This method must cast self between &'a Self<'static> and &'a Self<'a>. Read more
Source§

fn transform_owned(self) -> Cow<'a, T>

This method must cast self between Self<'static> and Self<'a>. Read more
Source§

unsafe fn make(from: Cow<'a, T>) -> Cow<'static, T>

This method can be used to cast away Self<'a>’s lifetime. Read more
Source§

fn transform_mut<F>(&'a mut self, f: F)
where F: 'static + for<'b> FnOnce(&'b mut Cow<'a, T>),

This method must cast self between &'a mut Self<'static> and &'a mut Self<'a>, and pass it to f. Read more
Source§

impl<'zf, B> ZeroFrom<'zf, Cow<'_, B>> for Cow<'zf, B>
where B: ToOwned + ?Sized,

Source§

fn zero_from(other: &'zf Cow<'_, B>) -> Cow<'zf, B>

Clone the other C into a struct that may retain references into C.
Source§

impl<'zf> ZeroFrom<'zf, String> for Cow<'zf, str>

Source§

fn zero_from(other: &'zf String) -> Cow<'zf, str>

Clone the other C into a struct that may retain references into C.
Source§

impl<'zf> ZeroFrom<'zf, str> for Cow<'zf, str>

Source§

fn zero_from(other: &'zf str) -> Cow<'zf, str>

Clone the other C into a struct that may retain references into C.
Source§

impl<B> DerefPure for Cow<'_, B>
where B: ToOwned + ?Sized, <B as ToOwned>::Owned: Borrow<B>,

1.0.0 · Source§

impl<B> Eq for Cow<'_, B>
where B: Eq + ToOwned + ?Sized,