pub struct RestrictedString<L: CharSet> { /* private fields */ }
Expand description

A generic restricted character string.

Restricted character strings essentially are a sequence of characters from a specific character set mapped into a sequence of octets. In BER, these are in fact encoded just like an OctetString with a different tag. Consequently, this type is a wrapper around OctetString that makes sure that the sequence of octets is correctly encoded for the given character set.

As usual, you can parse a restricted character string from encoded data by way of the take_from and from_content methods. Alternatively, you can create a new value from a String or str via the from_string and from_str associated functions.

Conversely, a restricted character string can be converted into a string by way of the to_string and to_str methods.

In addition, the restricted character string mirrors the standard library’s string types by dereffing to OctetString and using the octet string’s iterators. In addition, the chars method provides an iterator over the characters encoded in the string.

Implementations

Creates a new character string from an octet string.

If the octet string contains octet sequences that are not valid for the character set, an appropriate error will be returned.

Creates a new character string from a String.

If the string’s internal representation is identical to the encoding of restricted character string, the string will be reused and no allocation occurs. Otherwise, a new bytes value is created.

If the string cannot be encoded in the character set, an error is returned.

Returns an iterator over the character in the character string.

Converts the string into its underlying bytes.

Note that the bytes value will contain the raw octets of the string which are not necessarily a valid Rust string.

Takes a single character set value from constructed value content.

If there is no next value, if the next value does not have the natural tag appropriate for this character set implementation, or if it does not contain a correctly encoded character string, a malformed error is returned.

Takes a character set from content.

Returns a value encoder for the character string with the natural tag.

Returns a value encoder for the character string with the given tag.

Returns a value encoder for the character string with the natural tag.

Returns a value encoder for the character string with the given tag.

Methods from Deref<Target = OctetString>

Returns an iterator over the parts of the octet string.

The iterator will produce &[u8] which, when appended produce the complete content of the octet string.

Returns an iterator over the individual octets of the string.

Returns a reference to the complete content if possible.

The method will return a bytes slice of the content if the octet string was encoded as a single primitive value or None otherwise.

This is guaranteed to return some slice if the value was produced by decoding in DER mode.

Produces a bytes value with the string’s content.

If the octet string was encoded as a single primitive value, the method will simply clone the content. Otherwise it will produce an entirely new bytes value from the concatenated content of all the primitive values.

Returns the length of the content.

This is not the length of the encoded value but of the actual octet string.

Returns whether the content is empty.

Returns a value encoder for the octet string using the natural tag.

Returns a value encoder for the octet string using the given tag.

Trait Implementations

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

The resulting type after dereferencing.

Dereferences the value.

Formats the value using the given formatter. Read more

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

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

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

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

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.