SingletonMap

Struct SingletonMap 

Source
pub struct SingletonMap<V>(/* private fields */);
Expand description

A map that uses types as keys and stores values of a single type V.

This data structure allows you to associate values with types as keys. For example, you could map u8 to a String description, i8 to another String description, etc., all within the same SingletonMap<String>.

§Examples

use singletons::SingletonMap;

let mut map: SingletonMap<String> = SingletonMap::new();
map.insert::<u8>("An unsigned 8-bit integer".to_string());
map.insert::<i8>("A signed 8-bit integer".to_string());

assert_eq!(map.get::<u8>(), Some(&"An unsigned 8-bit integer".to_string()));
assert_eq!(map.get::<i8>(), Some(&"A signed 8-bit integer".to_string()));

Implementations§

Source§

impl<V> SingletonMap<V>

Source

pub fn new() -> Self

Creates an empty SingletonMap.

The map is initially created with a capacity of 0, so it will not allocate until an element is inserted.

§Examples
use singletons::SingletonMap;
let mut map: SingletonMap<String> = SingletonMap::new();
Examples found in repository?
examples/map_overview.rs (line 5)
3fn main() {
4    // Create a map that stores String descriptions for different types
5    let mut type_descriptions: SingletonMap<String> = SingletonMap::new();
6
7    // Insert descriptions for various types
8    type_descriptions.insert::<u8>("An unsigned 8-bit integer (0 to 255)".to_string());
9    type_descriptions.insert::<i8>("A signed 8-bit integer (-128 to 127)".to_string());
10    type_descriptions.insert::<u16>("An unsigned 16-bit integer".to_string());
11    type_descriptions.insert::<String>("A heap-allocated string".to_string());
12    type_descriptions.insert::<Vec<u32>>("A vector of 32-bit integers".to_string());
13
14    // Retrieve descriptions
15    println!("u8: {}", type_descriptions.get::<u8>().unwrap());
16    println!("i8: {}", type_descriptions.get::<i8>().unwrap());
17    println!("String: {}", type_descriptions.get::<String>().unwrap());
18
19    // Modify a description
20    if let Some(desc) = type_descriptions.get_mut::<u16>() {
21        desc.push_str(" (0 to 65,535)");
22    }
23    println!("u16: {}", type_descriptions.get::<u16>().unwrap());
24
25    // Use entry API
26    type_descriptions
27        .entry::<f64>()
28        .or_insert("A 64-bit floating-point number".to_string());
29
30    // Update existing entry
31    type_descriptions
32        .entry::<u8>()
33        .and_modify(|desc| desc.push_str(" - commonly used for bytes"))
34        .or_insert("Should not be inserted".to_string());
35
36    println!("\nAll type descriptions:");
37    for (type_key, description) in type_descriptions.iter() {
38        println!("  {}: {}", type_key.as_name(), description);
39    }
40
41    println!("\nTotal types documented: {}", type_descriptions.len());
42
43    // Example with default values
44    let mut counters: SingletonMap<i32> = SingletonMap::new();
45    *counters.get_or_insert_default::<u8>() += 5;
46    *counters.get_or_insert_default::<i8>() -= 3;
47
48    println!("\nCounters:");
49    println!("  u8 counter: {}", counters.get::<u8>().unwrap());
50    println!("  i8 counter: {}", counters.get::<i8>().unwrap());
51}
Source

pub fn with_capacity(capacity: usize) -> Self

Creates an empty SingletonMap with at least the specified capacity.

The map will be able to hold at least capacity elements without reallocating.

§Examples
use singletons::SingletonMap;
let mut map: SingletonMap<String> = SingletonMap::with_capacity(10);
Source

pub fn capacity(&self) -> usize

Returns the number of elements the map can hold without reallocating.

Source

pub fn len(&self) -> usize

Returns the number of elements currently in the map.

Examples found in repository?
examples/map_overview.rs (line 41)
3fn main() {
4    // Create a map that stores String descriptions for different types
5    let mut type_descriptions: SingletonMap<String> = SingletonMap::new();
6
7    // Insert descriptions for various types
8    type_descriptions.insert::<u8>("An unsigned 8-bit integer (0 to 255)".to_string());
9    type_descriptions.insert::<i8>("A signed 8-bit integer (-128 to 127)".to_string());
10    type_descriptions.insert::<u16>("An unsigned 16-bit integer".to_string());
11    type_descriptions.insert::<String>("A heap-allocated string".to_string());
12    type_descriptions.insert::<Vec<u32>>("A vector of 32-bit integers".to_string());
13
14    // Retrieve descriptions
15    println!("u8: {}", type_descriptions.get::<u8>().unwrap());
16    println!("i8: {}", type_descriptions.get::<i8>().unwrap());
17    println!("String: {}", type_descriptions.get::<String>().unwrap());
18
19    // Modify a description
20    if let Some(desc) = type_descriptions.get_mut::<u16>() {
21        desc.push_str(" (0 to 65,535)");
22    }
23    println!("u16: {}", type_descriptions.get::<u16>().unwrap());
24
25    // Use entry API
26    type_descriptions
27        .entry::<f64>()
28        .or_insert("A 64-bit floating-point number".to_string());
29
30    // Update existing entry
31    type_descriptions
32        .entry::<u8>()
33        .and_modify(|desc| desc.push_str(" - commonly used for bytes"))
34        .or_insert("Should not be inserted".to_string());
35
36    println!("\nAll type descriptions:");
37    for (type_key, description) in type_descriptions.iter() {
38        println!("  {}: {}", type_key.as_name(), description);
39    }
40
41    println!("\nTotal types documented: {}", type_descriptions.len());
42
43    // Example with default values
44    let mut counters: SingletonMap<i32> = SingletonMap::new();
45    *counters.get_or_insert_default::<u8>() += 5;
46    *counters.get_or_insert_default::<i8>() -= 3;
47
48    println!("\nCounters:");
49    println!("  u8 counter: {}", counters.get::<u8>().unwrap());
50    println!("  i8 counter: {}", counters.get::<i8>().unwrap());
51}
Source

pub fn is_empty(&self) -> bool

Returns true if the map contains no elements.

Source

pub fn clear(&mut self)

Clears the map, removing all key-value pairs.

Source

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

Reserves capacity for at least additional more elements.

Source

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

Tries to reserve capacity for at least additional more elements.

Source

pub fn shrink_to_fit(&mut self)

Shrinks the capacity of the map as much as possible.

Source

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

Shrinks the capacity of the map as much as possible, but not less than min_capacity.

Source

pub fn insert<K: 'static>(&mut self, value: V) -> Option<V>

Inserts a value into the map with the type K as the key.

If the map did not have this type as a key, None is returned. If the map did have this type as a key, the value is updated and the old value is returned.

§Examples
use singletons::SingletonMap;

let mut map = SingletonMap::new();
assert_eq!(map.insert::<u8>("first".to_string()), None);
assert_eq!(map.insert::<u8>("second".to_string()), Some("first".to_string()));
Examples found in repository?
examples/map_overview.rs (line 8)
3fn main() {
4    // Create a map that stores String descriptions for different types
5    let mut type_descriptions: SingletonMap<String> = SingletonMap::new();
6
7    // Insert descriptions for various types
8    type_descriptions.insert::<u8>("An unsigned 8-bit integer (0 to 255)".to_string());
9    type_descriptions.insert::<i8>("A signed 8-bit integer (-128 to 127)".to_string());
10    type_descriptions.insert::<u16>("An unsigned 16-bit integer".to_string());
11    type_descriptions.insert::<String>("A heap-allocated string".to_string());
12    type_descriptions.insert::<Vec<u32>>("A vector of 32-bit integers".to_string());
13
14    // Retrieve descriptions
15    println!("u8: {}", type_descriptions.get::<u8>().unwrap());
16    println!("i8: {}", type_descriptions.get::<i8>().unwrap());
17    println!("String: {}", type_descriptions.get::<String>().unwrap());
18
19    // Modify a description
20    if let Some(desc) = type_descriptions.get_mut::<u16>() {
21        desc.push_str(" (0 to 65,535)");
22    }
23    println!("u16: {}", type_descriptions.get::<u16>().unwrap());
24
25    // Use entry API
26    type_descriptions
27        .entry::<f64>()
28        .or_insert("A 64-bit floating-point number".to_string());
29
30    // Update existing entry
31    type_descriptions
32        .entry::<u8>()
33        .and_modify(|desc| desc.push_str(" - commonly used for bytes"))
34        .or_insert("Should not be inserted".to_string());
35
36    println!("\nAll type descriptions:");
37    for (type_key, description) in type_descriptions.iter() {
38        println!("  {}: {}", type_key.as_name(), description);
39    }
40
41    println!("\nTotal types documented: {}", type_descriptions.len());
42
43    // Example with default values
44    let mut counters: SingletonMap<i32> = SingletonMap::new();
45    *counters.get_or_insert_default::<u8>() += 5;
46    *counters.get_or_insert_default::<i8>() -= 3;
47
48    println!("\nCounters:");
49    println!("  u8 counter: {}", counters.get::<u8>().unwrap());
50    println!("  i8 counter: {}", counters.get::<i8>().unwrap());
51}
Source

pub fn get<K: 'static>(&self) -> Option<&V>

Returns a reference to the value corresponding to the type key K.

§Examples
use singletons::SingletonMap;

let mut map = SingletonMap::new();
map.insert::<u8>("value".to_string());
assert_eq!(map.get::<u8>(), Some(&"value".to_string()));
assert_eq!(map.get::<i8>(), None);
Examples found in repository?
examples/map_overview.rs (line 15)
3fn main() {
4    // Create a map that stores String descriptions for different types
5    let mut type_descriptions: SingletonMap<String> = SingletonMap::new();
6
7    // Insert descriptions for various types
8    type_descriptions.insert::<u8>("An unsigned 8-bit integer (0 to 255)".to_string());
9    type_descriptions.insert::<i8>("A signed 8-bit integer (-128 to 127)".to_string());
10    type_descriptions.insert::<u16>("An unsigned 16-bit integer".to_string());
11    type_descriptions.insert::<String>("A heap-allocated string".to_string());
12    type_descriptions.insert::<Vec<u32>>("A vector of 32-bit integers".to_string());
13
14    // Retrieve descriptions
15    println!("u8: {}", type_descriptions.get::<u8>().unwrap());
16    println!("i8: {}", type_descriptions.get::<i8>().unwrap());
17    println!("String: {}", type_descriptions.get::<String>().unwrap());
18
19    // Modify a description
20    if let Some(desc) = type_descriptions.get_mut::<u16>() {
21        desc.push_str(" (0 to 65,535)");
22    }
23    println!("u16: {}", type_descriptions.get::<u16>().unwrap());
24
25    // Use entry API
26    type_descriptions
27        .entry::<f64>()
28        .or_insert("A 64-bit floating-point number".to_string());
29
30    // Update existing entry
31    type_descriptions
32        .entry::<u8>()
33        .and_modify(|desc| desc.push_str(" - commonly used for bytes"))
34        .or_insert("Should not be inserted".to_string());
35
36    println!("\nAll type descriptions:");
37    for (type_key, description) in type_descriptions.iter() {
38        println!("  {}: {}", type_key.as_name(), description);
39    }
40
41    println!("\nTotal types documented: {}", type_descriptions.len());
42
43    // Example with default values
44    let mut counters: SingletonMap<i32> = SingletonMap::new();
45    *counters.get_or_insert_default::<u8>() += 5;
46    *counters.get_or_insert_default::<i8>() -= 3;
47
48    println!("\nCounters:");
49    println!("  u8 counter: {}", counters.get::<u8>().unwrap());
50    println!("  i8 counter: {}", counters.get::<i8>().unwrap());
51}
Source

pub fn get_mut<K: 'static>(&mut self) -> Option<&mut V>

Returns a mutable reference to the value corresponding to the type key K.

§Examples
use singletons::SingletonMap;

let mut map = SingletonMap::new();
map.insert::<u8>("value".to_string());
if let Some(v) = map.get_mut::<u8>() {
    v.push_str(" modified");
}
assert_eq!(map.get::<u8>(), Some(&"value modified".to_string()));
Examples found in repository?
examples/map_overview.rs (line 20)
3fn main() {
4    // Create a map that stores String descriptions for different types
5    let mut type_descriptions: SingletonMap<String> = SingletonMap::new();
6
7    // Insert descriptions for various types
8    type_descriptions.insert::<u8>("An unsigned 8-bit integer (0 to 255)".to_string());
9    type_descriptions.insert::<i8>("A signed 8-bit integer (-128 to 127)".to_string());
10    type_descriptions.insert::<u16>("An unsigned 16-bit integer".to_string());
11    type_descriptions.insert::<String>("A heap-allocated string".to_string());
12    type_descriptions.insert::<Vec<u32>>("A vector of 32-bit integers".to_string());
13
14    // Retrieve descriptions
15    println!("u8: {}", type_descriptions.get::<u8>().unwrap());
16    println!("i8: {}", type_descriptions.get::<i8>().unwrap());
17    println!("String: {}", type_descriptions.get::<String>().unwrap());
18
19    // Modify a description
20    if let Some(desc) = type_descriptions.get_mut::<u16>() {
21        desc.push_str(" (0 to 65,535)");
22    }
23    println!("u16: {}", type_descriptions.get::<u16>().unwrap());
24
25    // Use entry API
26    type_descriptions
27        .entry::<f64>()
28        .or_insert("A 64-bit floating-point number".to_string());
29
30    // Update existing entry
31    type_descriptions
32        .entry::<u8>()
33        .and_modify(|desc| desc.push_str(" - commonly used for bytes"))
34        .or_insert("Should not be inserted".to_string());
35
36    println!("\nAll type descriptions:");
37    for (type_key, description) in type_descriptions.iter() {
38        println!("  {}: {}", type_key.as_name(), description);
39    }
40
41    println!("\nTotal types documented: {}", type_descriptions.len());
42
43    // Example with default values
44    let mut counters: SingletonMap<i32> = SingletonMap::new();
45    *counters.get_or_insert_default::<u8>() += 5;
46    *counters.get_or_insert_default::<i8>() -= 3;
47
48    println!("\nCounters:");
49    println!("  u8 counter: {}", counters.get::<u8>().unwrap());
50    println!("  i8 counter: {}", counters.get::<i8>().unwrap());
51}
Source

pub fn remove<K: 'static>(&mut self) -> Option<V>

Removes a key-value pair from the map, returning the value if the type key K was present.

§Examples
use singletons::SingletonMap;

let mut map = SingletonMap::new();
map.insert::<u8>("value".to_string());
assert_eq!(map.remove::<u8>(), Some("value".to_string()));
assert_eq!(map.remove::<u8>(), None);
Source

pub fn contains_key<K: 'static>(&self) -> bool

Returns true if the map contains a value for the specified type key K.

§Examples
use singletons::SingletonMap;

let mut map = SingletonMap::new();
map.insert::<u8>("value".to_string());
assert!(map.contains_key::<u8>());
assert!(!map.contains_key::<i8>());
Source

pub fn keys(&self) -> Keys<'_, V>

Returns an iterator visiting all type keys in insertion order.

Source

pub fn values(&self) -> Values<'_, V>

Returns an iterator visiting all values in insertion order.

Source

pub fn values_mut(&mut self) -> ValuesMut<'_, V>

Returns an iterator visiting all values mutably in insertion order.

Source

pub fn iter(&self) -> Iter<'_, V>

Returns an iterator visiting all key-value pairs in insertion order.

Examples found in repository?
examples/map_overview.rs (line 37)
3fn main() {
4    // Create a map that stores String descriptions for different types
5    let mut type_descriptions: SingletonMap<String> = SingletonMap::new();
6
7    // Insert descriptions for various types
8    type_descriptions.insert::<u8>("An unsigned 8-bit integer (0 to 255)".to_string());
9    type_descriptions.insert::<i8>("A signed 8-bit integer (-128 to 127)".to_string());
10    type_descriptions.insert::<u16>("An unsigned 16-bit integer".to_string());
11    type_descriptions.insert::<String>("A heap-allocated string".to_string());
12    type_descriptions.insert::<Vec<u32>>("A vector of 32-bit integers".to_string());
13
14    // Retrieve descriptions
15    println!("u8: {}", type_descriptions.get::<u8>().unwrap());
16    println!("i8: {}", type_descriptions.get::<i8>().unwrap());
17    println!("String: {}", type_descriptions.get::<String>().unwrap());
18
19    // Modify a description
20    if let Some(desc) = type_descriptions.get_mut::<u16>() {
21        desc.push_str(" (0 to 65,535)");
22    }
23    println!("u16: {}", type_descriptions.get::<u16>().unwrap());
24
25    // Use entry API
26    type_descriptions
27        .entry::<f64>()
28        .or_insert("A 64-bit floating-point number".to_string());
29
30    // Update existing entry
31    type_descriptions
32        .entry::<u8>()
33        .and_modify(|desc| desc.push_str(" - commonly used for bytes"))
34        .or_insert("Should not be inserted".to_string());
35
36    println!("\nAll type descriptions:");
37    for (type_key, description) in type_descriptions.iter() {
38        println!("  {}: {}", type_key.as_name(), description);
39    }
40
41    println!("\nTotal types documented: {}", type_descriptions.len());
42
43    // Example with default values
44    let mut counters: SingletonMap<i32> = SingletonMap::new();
45    *counters.get_or_insert_default::<u8>() += 5;
46    *counters.get_or_insert_default::<i8>() -= 3;
47
48    println!("\nCounters:");
49    println!("  u8 counter: {}", counters.get::<u8>().unwrap());
50    println!("  i8 counter: {}", counters.get::<i8>().unwrap());
51}
Source

pub fn iter_mut(&mut self) -> IterMut<'_, V>

Returns an iterator visiting all key-value pairs mutably in insertion order.

Source

pub fn entry<K: 'static>(&mut self) -> Entry<'_, V>

Gets the given type key’s corresponding entry in the map for in-place manipulation.

§Examples
use singletons::SingletonMap;

let mut map = SingletonMap::new();
map.entry::<u8>().or_insert("default".to_string());
assert_eq!(map.get::<u8>(), Some(&"default".to_string()));
Examples found in repository?
examples/map_overview.rs (line 27)
3fn main() {
4    // Create a map that stores String descriptions for different types
5    let mut type_descriptions: SingletonMap<String> = SingletonMap::new();
6
7    // Insert descriptions for various types
8    type_descriptions.insert::<u8>("An unsigned 8-bit integer (0 to 255)".to_string());
9    type_descriptions.insert::<i8>("A signed 8-bit integer (-128 to 127)".to_string());
10    type_descriptions.insert::<u16>("An unsigned 16-bit integer".to_string());
11    type_descriptions.insert::<String>("A heap-allocated string".to_string());
12    type_descriptions.insert::<Vec<u32>>("A vector of 32-bit integers".to_string());
13
14    // Retrieve descriptions
15    println!("u8: {}", type_descriptions.get::<u8>().unwrap());
16    println!("i8: {}", type_descriptions.get::<i8>().unwrap());
17    println!("String: {}", type_descriptions.get::<String>().unwrap());
18
19    // Modify a description
20    if let Some(desc) = type_descriptions.get_mut::<u16>() {
21        desc.push_str(" (0 to 65,535)");
22    }
23    println!("u16: {}", type_descriptions.get::<u16>().unwrap());
24
25    // Use entry API
26    type_descriptions
27        .entry::<f64>()
28        .or_insert("A 64-bit floating-point number".to_string());
29
30    // Update existing entry
31    type_descriptions
32        .entry::<u8>()
33        .and_modify(|desc| desc.push_str(" - commonly used for bytes"))
34        .or_insert("Should not be inserted".to_string());
35
36    println!("\nAll type descriptions:");
37    for (type_key, description) in type_descriptions.iter() {
38        println!("  {}: {}", type_key.as_name(), description);
39    }
40
41    println!("\nTotal types documented: {}", type_descriptions.len());
42
43    // Example with default values
44    let mut counters: SingletonMap<i32> = SingletonMap::new();
45    *counters.get_or_insert_default::<u8>() += 5;
46    *counters.get_or_insert_default::<i8>() -= 3;
47
48    println!("\nCounters:");
49    println!("  u8 counter: {}", counters.get::<u8>().unwrap());
50    println!("  i8 counter: {}", counters.get::<i8>().unwrap());
51}
Source§

impl<V: Default> SingletonMap<V>

Source

pub fn get_or_insert_default<K: 'static>(&mut self) -> &mut V

Returns a mutable reference to the value for type key K, inserting a default value if the key is not present.

§Examples
use singletons::SingletonMap;

let mut map: SingletonMap<String> = SingletonMap::new();
let value = map.get_or_insert_default::<u8>();
assert_eq!(value, &String::new());
Examples found in repository?
examples/map_overview.rs (line 45)
3fn main() {
4    // Create a map that stores String descriptions for different types
5    let mut type_descriptions: SingletonMap<String> = SingletonMap::new();
6
7    // Insert descriptions for various types
8    type_descriptions.insert::<u8>("An unsigned 8-bit integer (0 to 255)".to_string());
9    type_descriptions.insert::<i8>("A signed 8-bit integer (-128 to 127)".to_string());
10    type_descriptions.insert::<u16>("An unsigned 16-bit integer".to_string());
11    type_descriptions.insert::<String>("A heap-allocated string".to_string());
12    type_descriptions.insert::<Vec<u32>>("A vector of 32-bit integers".to_string());
13
14    // Retrieve descriptions
15    println!("u8: {}", type_descriptions.get::<u8>().unwrap());
16    println!("i8: {}", type_descriptions.get::<i8>().unwrap());
17    println!("String: {}", type_descriptions.get::<String>().unwrap());
18
19    // Modify a description
20    if let Some(desc) = type_descriptions.get_mut::<u16>() {
21        desc.push_str(" (0 to 65,535)");
22    }
23    println!("u16: {}", type_descriptions.get::<u16>().unwrap());
24
25    // Use entry API
26    type_descriptions
27        .entry::<f64>()
28        .or_insert("A 64-bit floating-point number".to_string());
29
30    // Update existing entry
31    type_descriptions
32        .entry::<u8>()
33        .and_modify(|desc| desc.push_str(" - commonly used for bytes"))
34        .or_insert("Should not be inserted".to_string());
35
36    println!("\nAll type descriptions:");
37    for (type_key, description) in type_descriptions.iter() {
38        println!("  {}: {}", type_key.as_name(), description);
39    }
40
41    println!("\nTotal types documented: {}", type_descriptions.len());
42
43    // Example with default values
44    let mut counters: SingletonMap<i32> = SingletonMap::new();
45    *counters.get_or_insert_default::<u8>() += 5;
46    *counters.get_or_insert_default::<i8>() -= 3;
47
48    println!("\nCounters:");
49    println!("  u8 counter: {}", counters.get::<u8>().unwrap());
50    println!("  i8 counter: {}", counters.get::<i8>().unwrap());
51}

Trait Implementations§

Source§

impl<V: Clone> Clone for SingletonMap<V>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0§

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

Performs copy-assignment from source. Read more
Source§

impl<V: Debug> Debug for SingletonMap<V>

Source§

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

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

impl<V: Default> Default for SingletonMap<V>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<V> Freeze for SingletonMap<V>

§

impl<V> RefUnwindSafe for SingletonMap<V>
where V: RefUnwindSafe,

§

impl<V> Send for SingletonMap<V>
where V: Send,

§

impl<V> Sync for SingletonMap<V>
where V: Sync,

§

impl<V> Unpin for SingletonMap<V>
where V: Unpin,

§

impl<V> UnwindSafe for SingletonMap<V>
where V: UnwindSafe,

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

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

§

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
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

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

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

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

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.