Type Alias json_syntax::object::Key
source · pub type Key = SmallString<[u8; 16]>;
Expand description
Object key.
Aliased Type§
struct Key { /* private fields */ }
Implementations
source§impl<A> SmallString<A>
impl<A> SmallString<A>
sourcepub fn new() -> SmallString<A>
pub fn new() -> SmallString<A>
Construct an empty string.
sourcepub fn with_capacity(n: usize) -> SmallString<A>
pub fn with_capacity(n: usize) -> SmallString<A>
Construct an empty string with enough capacity pre-allocated to store
at least n
bytes.
Will create a heap allocation only if n
is larger than the inline capacity.
sourcepub fn from_str(s: &str) -> SmallString<A>
pub fn from_str(s: &str) -> SmallString<A>
Construct a SmallString
by copying data from a &str
.
sourcepub fn from_string(s: String) -> SmallString<A>
pub fn from_string(s: String) -> SmallString<A>
Construct a SmallString
by using an existing allocation.
sourcepub fn from_buf(buf: A) -> Result<SmallString<A>, FromUtf8Error<A>>
pub fn from_buf(buf: A) -> Result<SmallString<A>, FromUtf8Error<A>>
Constructs a new SmallString
on the stack using UTF-8 bytes.
If the provided byte array is not valid UTF-8, an error is returned.
sourcepub unsafe fn from_buf_unchecked(buf: A) -> SmallString<A>
pub unsafe fn from_buf_unchecked(buf: A) -> SmallString<A>
Constructs a new SmallString
on the stack using the provided byte array
without checking that the array contains valid UTF-8.
§Safety
This function is unsafe because it does not check that the bytes passed
to it are valid UTF-8. If this constraint is violated, it may cause
memory unsafety issues, as the Rust standard library functions assume
that &str
s are valid UTF-8.
sourcepub fn inline_size(&self) -> usize
pub fn inline_size(&self) -> usize
The maximum number of bytes this string can hold inline.
sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the number of bytes this string can hold without reallocating.
sourcepub fn spilled(&self) -> bool
pub fn spilled(&self) -> bool
Returns true
if the data has spilled into a separate heap-allocated buffer.
sourcepub fn drain(&mut self) -> Drain<'_>
pub fn drain(&mut self) -> Drain<'_>
Empties the string and returns an iterator over its former contents.
sourcepub fn push(&mut self, ch: char)
pub fn push(&mut self, ch: char)
Appends the given char
to the end of this string.
§Examples
use smallstr::SmallString;
let mut s: SmallString<[u8; 8]> = SmallString::from("foo");
s.push('x');
assert_eq!(s, "foox");
sourcepub fn push_str(&mut self, s: &str)
pub fn push_str(&mut self, s: &str)
Appends the given string slice to the end of this string.
§Examples
use smallstr::SmallString;
let mut s: SmallString<[u8; 8]> = SmallString::from("foo");
s.push_str("bar");
assert_eq!(s, "foobar");
sourcepub fn pop(&mut self) -> Option<char>
pub fn pop(&mut self) -> Option<char>
Removes the last character from this string and returns it.
Returns None
if the string is empty.
sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Ensures that this string’s capacity is at least additional
bytes larger
than its length.
The capacity may be increased by more than additional
bytes in order to
prevent frequent reallocations.
sourcepub fn reserve_exact(&mut self, additional: usize)
pub fn reserve_exact(&mut self, additional: usize)
Ensures that this string’s capacity is additional
bytes larger than
its length.
sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrink the capacity of the string as much as possible.
When possible, this will move the data from an external heap buffer to the string’s inline storage.
sourcepub fn truncate(&mut self, len: usize)
pub fn truncate(&mut self, len: usize)
Shorten the string, keeping the first len
bytes.
This does not reallocate. If you want to shrink the string’s capacity,
use shrink_to_fit
after truncating.
§Panics
If len
does not lie on a char
boundary.
sourcepub fn as_mut_str(&mut self) -> &mut str
pub fn as_mut_str(&mut self) -> &mut str
Extracts a string slice containing the entire string.
sourcepub fn remove(&mut self, idx: usize) -> char
pub fn remove(&mut self, idx: usize) -> char
Removes a char
from this string at a byte position and returns it.
§Panics
If idx
does not lie on a char
boundary.
sourcepub fn insert(&mut self, idx: usize, ch: char)
pub fn insert(&mut self, idx: usize, ch: char)
Inserts a char
into this string at the given byte position.
§Panics
If idx
does not lie on char
boundaries.
sourcepub fn insert_str(&mut self, idx: usize, s: &str)
pub fn insert_str(&mut self, idx: usize, s: &str)
Inserts a &str
into this string at the given byte position.
§Panics
If idx
does not lie on char
boundaries.
sourcepub unsafe fn as_mut_vec(&mut self) -> &mut SmallVec<A>
pub unsafe fn as_mut_vec(&mut self) -> &mut SmallVec<A>
Returns a mutable reference to the contents of the SmallString
.
§Safety
This function is unsafe because it does not check that the bytes passed
to it are valid UTF-8. If this constraint is violated, it may cause
memory unsafety issues, as the Rust standard library functions assume
that &str
s are valid UTF-8.
sourcepub fn into_string(self) -> String
pub fn into_string(self) -> String
Converts the SmallString
into a String
, without reallocating if the
SmallString
has already spilled onto the heap.
sourcepub fn into_boxed_str(self) -> Box<str>
pub fn into_boxed_str(self) -> Box<str>
Converts the SmallString
into a Box<str>
, without reallocating if the
SmallString
has already spilled onto the heap.
Note that this will drop excess capacity.
sourcepub fn into_inner(self) -> Result<A, SmallString<A>>
pub fn into_inner(self) -> Result<A, SmallString<A>>
Convert the SmallString
into A
, if possible. Otherwise, return Err(self)
.
This method returns Err(self)
if the SmallString
is too short
(and the A
contains uninitialized elements) or if the SmallString
is too long
(and the elements have been spilled to the heap).
sourcepub fn retain<F>(&mut self, f: F)
pub fn retain<F>(&mut self, f: F)
Retains only the characters specified by the predicate.
In other words, removes all characters c
such that f(c)
returns false
.
This method operates in place and preserves the order of retained
characters.
§Examples
use smallstr::SmallString;
let mut s: SmallString<[u8; 16]> = SmallString::from("f_o_ob_ar");
s.retain(|c| c != '_');
assert_eq!(s, "foobar");
Trait Implementations
source§impl<A> Write for SmallString<A>
impl<A> Write for SmallString<A>
source§impl<A> Deref for SmallString<A>
impl<A> Deref for SmallString<A>
source§impl<A> Default for SmallString<A>
impl<A> Default for SmallString<A>
source§fn default() -> SmallString<A>
fn default() -> SmallString<A>
source§impl<'a, A> PartialEq<str> for SmallString<A>
impl<'a, A> PartialEq<str> for SmallString<A>
source§impl<'a, A> PartialEq<&'a str> for SmallString<A>
impl<'a, A> PartialEq<&'a str> for SmallString<A>
source§impl<A, B> PartialEq<SmallString<B>> for SmallString<A>
impl<A, B> PartialEq<SmallString<B>> for SmallString<A>
source§fn eq(&self, rhs: &SmallString<B>) -> bool
fn eq(&self, rhs: &SmallString<B>) -> bool
self
and other
values to be equal, and is used
by ==
.source§fn ne(&self, rhs: &SmallString<B>) -> bool
fn ne(&self, rhs: &SmallString<B>) -> bool
!=
. The default implementation is almost always
sufficient, and should not be overridden without very good reason.source§impl<'a, A> PartialEq<String> for SmallString<A>
impl<'a, A> PartialEq<String> for SmallString<A>
source§impl<'a, A> PartialEq<Cow<'a, str>> for SmallString<A>
impl<'a, A> PartialEq<Cow<'a, str>> for SmallString<A>
source§impl<A> IndexMut<RangeFull> for SmallString<A>
impl<A> IndexMut<RangeFull> for SmallString<A>
source§impl<A> Debug for SmallString<A>
impl<A> Debug for SmallString<A>
source§impl<A> Borrow<str> for SmallString<A>
impl<A> Borrow<str> for SmallString<A>
source§impl<A> Borrow<[u8]> for SmallString<A>
impl<A> Borrow<[u8]> for SmallString<A>
source§impl<A> From<char> for SmallString<A>
impl<A> From<char> for SmallString<A>
source§fn from(ch: char) -> SmallString<A>
fn from(ch: char) -> SmallString<A>
source§impl<'a, A> From<&'a str> for SmallString<A>
impl<'a, A> From<&'a str> for SmallString<A>
source§fn from(s: &str) -> SmallString<A>
fn from(s: &str) -> SmallString<A>
source§impl<A> From<String> for SmallString<A>
impl<A> From<String> for SmallString<A>
source§fn from(s: String) -> SmallString<A>
fn from(s: String) -> SmallString<A>
source§impl<A> Display for SmallString<A>
impl<A> Display for SmallString<A>
source§impl<A> Hash for SmallString<A>
impl<A> Hash for SmallString<A>
source§impl<A> PartialOrd for SmallString<A>
impl<A> PartialOrd for SmallString<A>
source§fn partial_cmp(&self, rhs: &SmallString<A>) -> Option<Ordering>
fn partial_cmp(&self, rhs: &SmallString<A>) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<A> AsMut<str> for SmallString<A>
impl<A> AsMut<str> for SmallString<A>
source§impl<A> AsRef<str> for SmallString<A>
impl<A> AsRef<str> for SmallString<A>
source§impl<A> AsRef<[u8]> for SmallString<A>
impl<A> AsRef<[u8]> for SmallString<A>
source§impl<A> Extend<char> for SmallString<A>
impl<A> Extend<char> for SmallString<A>
source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = char>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = char>,
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl<A> Extend<String> for SmallString<A>
impl<A> Extend<String> for SmallString<A>
source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = String>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = String>,
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl<'a, A> Extend<&'a str> for SmallString<A>
impl<'a, A> Extend<&'a str> for SmallString<A>
source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = &'a str>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = &'a str>,
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl<'a, A> Extend<Cow<'a, str>> for SmallString<A>
impl<'a, A> Extend<Cow<'a, str>> for SmallString<A>
source§fn extend<I>(&mut self, iter: I)
fn extend<I>(&mut self, iter: I)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl<'a, A> Extend<&'a char> for SmallString<A>
impl<'a, A> Extend<&'a char> for SmallString<A>
source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = &'a char>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = &'a char>,
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl<A> BorrowMut<str> for SmallString<A>
impl<A> BorrowMut<str> for SmallString<A>
source§fn borrow_mut(&mut self) -> &mut str
fn borrow_mut(&mut self) -> &mut str
source§impl<A> Clone for SmallString<A>
impl<A> Clone for SmallString<A>
source§fn clone(&self) -> SmallString<A>
fn clone(&self) -> SmallString<A>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more