- https://doc.rust-lang.org/std/string/struct.String.html
2022-11-3 · There are two options that would work instead. The first would be to change the line example_func(&example_string); to example_func(example_string.as_str());, using the method as_str() to explicitly extract the string slice containing the string. The second way changes example_func(&example_string); to example_func(&*example_string);.In this case we are …
- https://doc.rust-lang.org/std/iter/trait.Iterator.html
2022-11-3 · An interface for dealing with iterators. Returns the bounds on the remaining length of the iterator. Specifically, size_hint() returns a tuple where the first element is the lower bound, and the second element is the upper bound. The second half of the tuple that is returned is an Option<usize>.A None here means that either there is no known upper bound, or the upper …
- https://doc.rust-lang.org/std/iter
2022-11-3 · In other words, all Iterators implement IntoIterator, by just returning themselves.This means two things: If you’re writing an Iterator, you can use it with a for loop.; If you’re creating a collection, implementing IntoIterator for it will allow your collection to be used with the for loop.; Iterating by reference. Since into_iter() takes self by value, using a for loop to iterate over a ...
- https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
2022-11-3 · Running this code will print *waving arms furiously*, showing that Rust called the fly method implemented on Human directly. To call the fly methods from either the Pilot trait or the Wizard trait, we need to use more explicit syntax to specify which fly method we mean. Listing 19-18 demonstrates this syntax. Filename: src/main.rs
- https://doc.rust-lang.org/std/rc/struct.Rc.html
2022-11-3 · Decrements the strong reference count on the Rc<T> associated with the provided pointer by one.. Safety. The pointer must have been obtained through Rc::into_raw, and the associated Rc instance must be valid (i.e. the strong count must be at least 1) when invoking this method. This method can be used to release the final Rc and backing storage, but should not …
- https://doc.rust-lang.org/std/fmt
2022-11-3 · The format functions provided by Rust’s standard library do not have any concept of locale and will produce the same results on all systems regardless of user configuration. For example, the following code will always print 1.5 even if the system locale uses a decimal separator other than a dot.
- https://doc.rust-lang.org/std/primitive.pointer.html
2022-11-3 · Raw, unsafe pointers, *const T, and *mut T. See also the std::ptr module.. Working with raw pointers in Rust is uncommon, typically limited to a few patterns. Raw pointers can be unaligned or null.However, when a raw pointer is dereferenced (using the * operator), it must be non-null and aligned.. Storing through a raw pointer using *ptr = data calls drop on the old …
- https://doc.rust-lang.org/std/vec/struct.Vec.html
2022-11-3 · Constructs a new, empty Vec<T> with at least the specified capacity.. The vector will be able to hold at least capacity elements without reallocating. This method is allowed to allocate for more elements than capacity.If capacity is 0, the vector will not allocate.. It is important to note that although the returned vector has the minimum capacity specified, the vector will have a …
- https://doc.rust-lang.org/std/collections/struct.HashMap.html
2022-11-3 · Creates an empty HashMap with at least the specified capacity, using hasher to hash the keys.. The hash map will be able to hold at least capacity elements without reallocating. This method is allowed to allocate for more elements than capacity.If capacity is 0, the hash map will not allocate.. Warning: hasher is normally randomly generated, and is designed to allow …
- https://doc.rust-lang.org/std/ffi/struct.CString.html
2022-11-3 · Retakes ownership of a CString that was transferred to C via CString::into_raw.. Additionally, the length of the string will be recalculated from the pointer. Safety. This should only ever be called with a pointer that was earlier obtained by calling CString::into_raw.Other usage (e.g., trying to take ownership of a string that was allocated by foreign code) is likely to lead to …