Info

Struct Info 

Source
pub struct Info {
    pub name: String,
    pub piece_length: u64,
    pub pieces: PieceHashes,
    pub files: Vec<File>,
    pub total_length: u64,
    pub private: bool,
    pub meta_version: Option<u8>,
}
Expand description

The info dictionary from a torrent file.

Contains the core metadata that identifies the torrent content. The hash of this dictionary (in bencode format) is the info hash.

Fields§

§name: String

Suggested name for the file or directory.

§piece_length: u64

Number of bytes per piece.

§pieces: PieceHashes

Piece hashes for verification (v1 SHA1, v2 merkle layers, or both).

§files: Vec<File>

List of files in the torrent.

§total_length: u64

Total size of all files combined.

§private: bool

If true, clients should only use trackers in the metainfo (no DHT/PEX).

§meta_version: Option<u8>

The meta version field from v2 torrents (2 for BEP-52).

Implementations§

Source§

impl Info

Source

pub fn piece_count(&self) -> usize

Returns the number of pieces for v1-style piece indexing.

For v1 and hybrid torrents, this returns the piece count. For pure v2 torrents, this calculates based on files and piece length.

Source

pub fn is_v1(&self) -> bool

Returns true if this is a v1-only torrent.

Source

pub fn is_v2(&self) -> bool

Returns true if this is a v2-only torrent.

Source

pub fn is_hybrid(&self) -> bool

Returns true if this is a hybrid torrent (both v1 and v2).

Source

pub fn supports_v1(&self) -> bool

Returns true if this torrent supports v1 protocol.

Source

pub fn supports_v2(&self) -> bool

Returns true if this torrent supports v2 protocol.

Source

pub fn get_v1_piece_hash(&self, piece_index: usize) -> Option<[u8; 20]>

Gets the v1 piece hash for a given piece index.

Returns None for pure v2 torrents or invalid indices.

Source

pub fn get_v2_piece_hash( &self, file_index: usize, piece_index: usize, ) -> Option<[u8; 32]>

Gets the v2 piece hash for a given file and piece index within that file.

For v2 torrents, pieces are per-file. This returns the layer hash for the given piece within the specified file.

Source

pub fn get_file_pieces_root(&self, file_index: usize) -> Option<[u8; 32]>

Gets the merkle root (pieces_root) for a file.

Returns None for v1 torrents or if the file has no pieces_root.

Source

pub fn file_piece_count(&self, file_index: usize) -> usize

Returns the number of pieces for a given file (v2 calculation).

For v2 torrents, each file has its own piece space.

Source

pub fn content_files(&self) -> impl Iterator<Item = &File>

Returns all non-padding files.

Source

pub fn padding_files(&self) -> impl Iterator<Item = &File>

Returns all padding files.

Source

pub fn get_v2_piece_hash_global( &self, global_piece_index: usize, ) -> Option<[u8; 32]>

Gets the v2 piece hash for a global piece index.

For v2 torrents, this maps the global piece index to the correct file and file-local piece index, then returns the layer hash.

For files that fit within a single piece (length <= piece_length), the pieces_root IS the layer hash (no piece layers entry).

Source

pub fn all_v2_piece_hashes(&self) -> Vec<[u8; 32]>

Builds a list of all v2 piece hashes in global piece order.

This flattens the per-file piece layers into a single list that can be used for storage verification.

Trait Implementations§

Source§

impl Clone for Info

Source§

fn clone(&self) -> Info

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Info

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Info

§

impl RefUnwindSafe for Info

§

impl Send for Info

§

impl Sync for Info

§

impl Unpin for Info

§

impl UnwindSafe for Info

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

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

Source§

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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

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

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

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more