Struct hls_m3u8::tags::ExtXByteRange[][src]

pub struct ExtXByteRange(_);
Expand description

Indicates that a MediaSegment is a sub-range of the resource identified by its URI.

Example

Constructing an ExtXByteRange:

assert_eq!(ExtXByteRange::from(22..55), ExtXByteRange::from(22..=54));

It is also possible to omit the start, in which case it assumes that the ExtXByteRange starts at the byte after the end of the previous ExtXByteRange or 0 if there is no previous one.

assert_eq!(ExtXByteRange::from(..55), ExtXByteRange::from(..=54));

Implementations

Adds num to the start and end of the range.

Example

let range = ExtXByteRange::from(10..22);
let nrange = range.saturating_add(5);

assert_eq!(nrange.len(), range.len());
assert_eq!(nrange.start(), range.start().map(|c| c + 5));

Overflow

If the range is saturated it will not overflow and instead stay at it’s current value.

let range = ExtXByteRange::from(5..usize::max_value());

// this would cause the end to overflow
let nrange = range.saturating_add(1);

// but the range remains unchanged
assert_eq!(range, nrange);

Note

The length of the range will remain unchanged, if the start is Some.

Subtracts num from the start and end of the range.

Example

let range = ExtXByteRange::from(10..22);
let nrange = range.saturating_sub(5);

assert_eq!(nrange.len(), range.len());
assert_eq!(nrange.start(), range.start().map(|c| c - 5));

Underflow

If the range is saturated it will not underflow and instead stay at it’s current value.

let range = ExtXByteRange::from(0..10);

// this would cause the start to underflow
let nrange = range.saturating_sub(1);

// but the range remains unchanged
assert_eq!(range, nrange);

Note

The length of the range will remain unchanged, if the start is Some.

Returns a shared reference to the underlying ByteRange.

Example

use hls_m3u8::types::ByteRange;

assert_eq!(
    ExtXByteRange::from(2..11).as_byte_range(),
    &ByteRange::from(2..11)
);

Methods from Deref<Target = ByteRange>

Returns the start of the ByteRange, if there is one.

Example

assert_eq!(ByteRange::from(0..5).start(), Some(0));
assert_eq!(ByteRange::from(..5).start(), None);

Returns the end of the ByteRange.

Example

assert_eq!(ByteRange::from(0..5).end(), 5);
assert_eq!(ByteRange::from(..=5).end(), 6);

Changes the length of the ByteRange.

Example

let mut range = ByteRange::from(0..5);
range.set_len(2);

assert_eq!(range, ByteRange::from(0..2));

range.set_len(200);
assert_eq!(range, ByteRange::from(0..200));

Note

The start will not be changed.

Sets the start of the ByteRange.

Example

assert_eq!(ByteRange::from(0..5).set_start(Some(5)).start(), Some(5));
assert_eq!(ByteRange::from(..5).set_start(Some(2)).start(), Some(2));

Panics

This function will panic, if the new_start is larger, than the end.

Returns the length, which is calculated by subtracting the end from the start. If the start is None a 0 is assumed.

Example

let range = ByteRange::from(1..16);

assert_eq!(range.len(), 15);

Returns true if the length is zero.

Example

let range = ByteRange::from(12..12);

assert_eq!(range.is_empty(), true);

Trait Implementations

The resulting type after applying the + operator.

Performs the + operation. Read more

Performs the += operation. Read more

Performs the conversion.

Performs the conversion.

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.

Mutably dereferences the value.

Formats the value using the given formatter. Read more

Performs the conversion.

Feeds this value into the given Hasher. Read more

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

Performs the conversion.

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

The resulting type after applying the - operator.

Performs the - operation. Read more

Performs the -= operation. Read more

The type returned in the event of a conversion error.

Performs the conversion.

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

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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.