Struct FsString

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

A type that represents a mutable and owned VEXos filesystem string, while being cheaply inter-convertible with Rust strings.

FsString is NOT null terminated. If you need to pass this to VEX SDK filesystem functions, create a CStr.

An FsString is to &FsStr as String is to &str; the former are owned, while the latter are borrowed references.

Implementations§

Source§

impl FsString

Source

pub const fn new() -> Self

Allocates a new, empty, FsString.

Source

pub unsafe fn from_encoded_bytes_unchecked(bytes: Vec<u8>) -> Self

Creates a new FsString from the raw encoded bytes.

§Safety

This function does not check if there are nul bytes withing or terminating the string. Passing an invalid FsString to VEX SDK functions can have unintended consequences, including undefined behavior.

Source

pub fn as_fs_str(&self) -> &FsStr

Borrows an FsString as an FsStr.

This is akin to taking a slice of the entire FsString

Source

pub fn into_encoded_bytes(self) -> Vec<u8>

Returns the raw encoded bytes of the FsString

Source

pub fn into_string(self) -> Result<String, FsString>

Converts the FsString to a String, or returns the original FsString on failure.

§Errors

This function will return the original string in the Err variant if the FsString was not valid UTF-8

Source

pub fn push<S: AsRef<FsStr>>(&mut self, s: S)

Extends the FsString with the given string.

As an example, the stored data in this example will be equivalent to “foobarbaz”:

let mut foo = FsString::new();
foo.push("foo");
foo.push("bar");
foo.push("baz");
Source

pub fn with_capacity(capacity: usize) -> Self

Creates a new FsString with the given capacity. For more information on capacity, look at the Vec::with_capacity documentation.

Source

pub fn clear(&mut self)

Clears all data from the FsString. This has no effect on the capacity of the FsString

§Examples
let mut string = FsString::with_capacity(100);
string.push("hello :3");
assert!(string.capacity() >= 100);
string.clear();
assert!(string.capacity() >= 100)
Source

pub fn capacity(&self) -> usize

Returns the capacity of the FsString. The capacity of the string will be equivalent to the maximum number of characters unless special characters are used.

Source

pub fn reserve(&mut self, additional: usize)

Reserves at least additional bytes in the FsString.

In order to reduce allocations, this function will often reserve more than additional bytes. For more information on the logic behind reserving bytes, see the Vec::reserve documentation.

Source

pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>

Attempts to reserve at least additional bytes in the FsString.

In order to reduce allocations, this function will often reserve more than additional bytes. For more information on the logic behind reserving bytes, see the Vec::reserve documentation.

§Errors

This function will error under the following conditions:

  • The capacity of the FsString has surpasses isize::MAX bytes
  • An allocation error occured while reserving space.
Source

pub fn reserve_exact(&mut self, additional: usize)

Reserves additional bytes in the FsString.

§Note

Reserving an exact amount of times can often negatively impact performace. you most likely want to use FsString::reserve

Source

pub fn try_reserve_exact( &mut self, additional: usize, ) -> Result<(), TryReserveError>

Attempts to reserve additional bytes in the FsString.

§Note

Reserving an exact amount of times can often negatively impact performace. you most likely want to use FsString::reserve

§Errors

This function will error under the following conditions:

  • The capacity of the FsString has surpasses isize::MAX bytes
  • An allocation error occured while reserving space.
Source

pub fn shrink_to_fit(&mut self)

Shrinks the capacity of the FsString as much as possible.

Depending on the allocator implementation, the FsString may still have extra capacity. See core::alloc::Allocator::shrink for more info.

Source

pub fn shrink_to(&mut self, min_capacity: usize)

Shrinks the capacity of the FsString to a lower bound.

Source

pub fn into_boxed_fs_str(self) -> Box<FsStr>

Consumes and converts this FsString into a Box<FsStr>. Excess capacity is discarded.

Source

pub fn leak<'a>(self) -> &'a mut FsStr

Consumes and leaks this FsString and converts it to a &FsStr.

Methods from Deref<Target = FsStr>§

Source

pub 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 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 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 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 Clone for FsString

Source§

fn clone(&self) -> FsString

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FsString

Source§

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

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

impl Default for FsString

Source§

fn default() -> FsString

Returns the “default value” for a type. Read more
Source§

impl Deref for FsString

Source§

type Target = FsStr

The resulting type after dereferencing.
Source§

fn deref(&self) -> &FsStr

Dereferences the value.
Source§

impl DerefMut for FsString

Source§

fn deref_mut(&mut self) -> &mut FsStr

Mutably dereferences the value.
Source§

impl<T: ?Sized + AsRef<FsStr>> From<&T> for FsString

Source§

fn from(s: &T) -> FsString

Copies any value implementing AsRef<FsStr> into a newly allocated FsString.

Source§

impl From<String> for FsString

Source§

fn from(value: String) -> Self

Converts to this type from the input type.
Source§

impl Hash for FsString

Source§

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

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

impl Index<RangeFull> for FsString

Source§

type Output = FsStr

The returned type after indexing.
Source§

fn index(&self, _index: RangeFull) -> &FsStr

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<RangeFull> for FsString

Source§

fn index_mut(&mut self, _index: RangeFull) -> &mut FsStr

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl Ord for FsString

Source§

fn cmp(&self, other: &FsString) -> 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
Source§

impl PartialEq for FsString

Source§

fn eq(&self, other: &FsString) -> 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 FsString

Source§

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

Source§

impl StructuralPartialEq for FsString

Auto Trait Implementations§

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

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.