Skip to main content

SessionEntry

Struct SessionEntry 

Source
pub struct SessionEntry {
Show 15 fields pub gid: u64, pub uris: Vec<String>, pub options: HashMap<String, String>, pub paused: bool, pub total_length: u64, pub completed_length: u64, pub upload_length: u64, pub download_speed: u64, pub status: String, pub error_code: Option<i32>, pub bitfield: Option<Vec<u8>>, pub num_pieces: Option<u32>, pub piece_length: Option<u32>, pub info_hash_hex: Option<String>, pub resume_offset: Option<u64>,
}
Expand description

Represents a single download task in a session file

This struct contains all information needed to resume a download task, including URIs, options, current progress, and status.

§Fields

  • gid - Unique global identifier for this download task
  • uris - List of source URLs (primary URL + mirrors)
  • options - Download configuration options as key-value pairs
  • paused - Whether this download is currently paused
  • total_length - Total size of the download in bytes
  • completed_length - Number of bytes already downloaded
  • upload_length - Number of bytes uploaded (for seeding)
  • download_speed - Current download speed in bytes/sec
  • status - Current status: “active”, “waiting”, “paused”, or “error”
  • error_code - Error code if status is “error”
  • bitfield - BitTorrent piece completion bitmap (BT only)
  • num_pieces - Number of pieces in torrent (BT only)
  • piece_length - Size of each piece in bytes (BT only)
  • info_hash_hex - Torrent info hash hex string (BT only)
  • resume_offset - File offset for HTTP/FTP resume support

Fields§

§gid: u64

Unique global identifier for this download task

§uris: Vec<String>

List of source URIs (primary URL + mirrors), tab-separated in serialized form

§options: HashMap<String, String>

Download configuration options as key-value pairs

§paused: bool

Whether this download is currently paused

§total_length: u64

Total size of the download in bytes (0 if unknown)

§completed_length: u64

Number of bytes already downloaded and verified

§upload_length: u64

Number of bytes uploaded (relevant for BitTorrent seeding)

§download_speed: u64

Current download speed in bytes/second

§status: String

Current status of the download: “active”, “waiting”, “paused”, “error”

§error_code: Option<i32>

Error code if the download is in error state

§bitfield: Option<Vec<u8>>

Completed piece bitmap encoded as hex string in file format None for non-BT downloads

§num_pieces: Option<u32>

Total number of pieces in the torrent None for non-BT downloads

§piece_length: Option<u32>

Size of each piece in bytes None for non-BT downloads

§info_hash_hex: Option<String>

Info hash of the torrent (hex string) for matching torrent files None for non-BT downloads

§resume_offset: Option<u64>

File offset where download should resume (for HTTP/FTP range requests) None if resumption is not applicable

Implementations§

Source§

impl SessionEntry

Source

pub fn new(gid: u64, uris: Vec<String>) -> Self

Creates a new SessionEntry with default values

§Arguments
  • gid - Unique identifier for this download task
  • uris - List of source URLs (at least one required)
§Returns

A new SessionEntry instance with sensible defaults:

  • paused: false
  • All progress fields: 0
  • status: “active”
  • All optional fields: None
§Example
use aria2_core::session::session_entry::SessionEntry;

let entry = SessionEntry::new(1, vec!["http://example.com/file.zip".to_string()]);
assert_eq!(entry.gid, 1);
assert_eq!(entry.uris.len(), 1);
assert!(!entry.paused);
assert_eq!(entry.status, "active");
Source

pub fn with_options(self, options: HashMap<String, String>) -> Self

Sets download options using builder pattern

§Arguments
  • options - HashMap of option key-value pairs
§Returns

Self for method chaining

§Example
use aria2_core::session::session_entry::SessionEntry;
use std::collections::HashMap;

let mut opts = HashMap::new();
opts.insert("split".to_string(), "4".to_string());
opts.insert("dir".to_string(), "/downloads".to_string());

let entry = SessionEntry::new(1, vec!["http://example.com/f".to_string()])
    .with_options(opts);
assert_eq!(entry.options.get("split").unwrap(), "4");
Source

pub fn paused(self) -> Self

Marks this entry as paused using builder pattern

§Returns

Self for method chaining

§Example
use aria2_core::session::session_entry::SessionEntry;

let entry = SessionEntry::new(1, vec!["http://example.com/f".to_string()])
    .paused();
assert!(entry.paused);
Source§

impl SessionEntry

Source

pub fn serialize(&self) -> String

Serializes this entry to the session file format

Produces a multi-line string representation suitable for writing to a session file. The format is compatible with aria2’s session format.

§Returns

String containing the serialized entry (including trailing newline)

§Format
uri1\turi2\turi3
 GID=hex_value
 [PAUSE=true]
 option_key=option_value
 TOTAL_LENGTH=...
 COMPLETED_LENGTH=...
 ...
§Example
use aria2_core::session::session_entry::SessionEntry;

let entry = SessionEntry::new(0xd270c8a2, vec!["http://example.com/file.zip".to_string()]);
let text = entry.serialize();
assert!(text.contains("http://example.com/file.zip"));
assert!(text.contains("GID=d270c8a2"));
Source

pub fn deserialize_line(text: &str) -> Result<SessionEntry>

Deserializes a single line of text into a SessionEntry

Parses a text block containing URI lines and property lines (lines starting with space) into a complete SessionEntry.

§Arguments
  • text - Multi-line string containing one entry’s data
§Returns

Result containing the deserialized SessionEntry or an error

§Note

This is a lower-level parsing function. For parsing multiple entries from a full session file, use crate::session::session_serializer::deserialize().

Trait Implementations§

Source§

impl Clone for SessionEntry

Source§

fn clone(&self) -> SessionEntry

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for SessionEntry

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + 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: Sized + 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