Struct FsStr

Source
pub struct FsStr { /* private fields */ }
Expand description

Borrowed reference to an VEXos filesystem OS string.

This type represents a borrowed reference to a string in VEXos’s preferred representation for filesystem paths.

Implementations§

Source§

impl FsStr

Source

pub fn new<'a, S: AsRef<Self> + 'a>(string: S) -> &'a Self

Coerces into an OsStr slice.

§Examples
use vexide::fs::FsStr;

let fs_str = FsStr::new("foo");
Source

pub const unsafe fn from_encoded_bytes_unchecked(bytes: &[u8]) -> &Self

Converts a slice of bytes to an FS string slice without checking that the string contains valid FsStr-encoded data.

§Safety

As the encoding is unspecified, callers must pass in bytes that originated as a mixture of validated UTF-8 and bytes from FsStr::as_encoded_bytes from within the same Rust version built for the same target platform.

Due to the encoding being self-synchronizing, the bytes from FsStr::as_encoded_bytes can be split either immediately before or immediately after any valid non-empty UTF-8 substring.

Source

pub const fn as_encoded_bytes(&self) -> &[u8]

Converts an FS string slice to a byte slice. To convert the byte slice back into an FS string slice, use the FsStr::from_encoded_bytes_unchecked function.

§Note

As the encoding is unspecified, any sub-slice of bytes that is not valid UTF-8 should be treated as opaque and only comparable within the same Rust version built for the same target platform. For example, sending the slice over the network or storing it in a file will likely result in incompatible byte slices.

Source

pub fn to_fs_string(&self) -> FsString

Copies this FsStr into an owned FsString.

§Examples
let fs_str = FsStr::new("foo");
let fs_string = fs_str.to_fs_string();
assert_eq!(ofs_string.as_encoded_bytes(), fs_str.as_encoded_bytes());
Source

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

Converts an FsStr into a UTF-8 encoded string.

Any non-UTF-8 sequences are replaced with the unicode U+FFFD REPLACEMENT CHARACTER.

Source

pub const fn is_empty(&self) -> bool

Checks whether or not the FsStr is empty.

§Examples
let fs_str = FsStr::new("");
assert!(fs_str.is_empty());

let fs_str = FsStr::new("foo");
assert!(!fs_str.is_empty());
Source

pub const fn len(&self) -> usize

Returns the length of the FsStr.

§Examples
let fs_str = FsStr::new("");
assert_eq!(fs_str.len(), 0);

let fs_str = FsStr::new("foo");
assert_eq!(fs_str.len(), 3);
Source

pub const fn display(&self) -> Display<'_>

Returns a Display which can be used to display FsStrs that may contain non-UTF-8 data. This may perform lossy conversions. For an implementation that escapes the data, use Debug.

Trait Implementations§

Source§

impl AsRef<FsStr> for FsStr

Source§

fn as_ref(&self) -> &FsStr

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

impl AsRef<FsStr> for str

Source§

fn as_ref(&self) -> &FsStr

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

impl Debug for FsStr

Source§

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

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

impl Hash for FsStr

Source§

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

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

impl Ord for FsStr

Source§

fn cmp(&self, other: &FsStr) -> Ordering

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

impl PartialEq for FsStr

Source§

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

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

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

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

impl PartialOrd for FsStr

Source§

fn partial_cmp(&self, other: &FsStr) -> 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 Eq for FsStr

Source§

impl StructuralPartialEq for FsStr

Auto Trait Implementations§

§

impl Freeze for FsStr

§

impl RefUnwindSafe for FsStr

§

impl Send for FsStr

§

impl !Sized for FsStr

§

impl Sync for FsStr

§

impl Unpin for FsStr

§

impl UnwindSafe for FsStr

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more