### Quick Torrent Download Example Source: https://docs.rs/librqbit/latest/librqbit/index.html This example demonstrates how to initialize a session, add a torrent from a magnet link, and wait for it to complete. Ensure the tokio runtime is available for async operations. ```rust use librqbit::*; tokio_test::block_on(async { let session = Session::new("/tmp/where-to-download".into()).await.unwrap(); let managed_torrent_handle = session.add_torrent( AddTorrent::from_url("magnet:?xt=urn:btih:cab507494d02ebb1178b38f2e9d7be299c86b862"), None // options ).await.unwrap().into_handle().unwrap(); managed_torrent_handle.wait_until_completed().await.unwrap(); }) ``` -------------------------------- ### Api::api_torrent_action_start Source: https://docs.rs/librqbit/latest/librqbit/api/struct.Api.html Asynchronously starts a torrent. ```APIDOC ## Api::api_torrent_action_start ### Description Asynchronously starts a torrent. ### Signature `pub async fn api_torrent_action_start(&self, idx: TorrentIdOrHash) -> Result` ``` -------------------------------- ### init for MmapFilesystemStorage Source: https://docs.rs/librqbit/latest/librqbit/storage/filesystem/struct.MmapFilesystemStorage.html Initializes the storage with shared torrent data and metadata. This is a required setup step before using the storage. ```rust fn init( &mut self, shared: &ManagedTorrentShared, metadata: &TorrentMetadata, ) -> Result<()> ``` -------------------------------- ### Default Implementation for AddTorrentOptions Source: https://docs.rs/librqbit/latest/librqbit/struct.AddTorrentOptions.html Provides the default configuration for AddTorrentOptions. This is useful when you need a basic setup without specifying every option. ```rust fn default() -> AddTorrentOptions ``` -------------------------------- ### librqbit_spawn Source: https://docs.rs/librqbit/latest/librqbit/fn.librqbit_spawn.html Spawns a future inside a tracing span, logging its start, finish, and periodically checking if it's still alive. ```APIDOC ## Function librqbit_spawn ### Description Spawn a future inside a tracing span, while logging it’s start, finish and periodically logging if it’s still alive. ### Signature ```rust pub fn librqbit_spawn( _name: &str, span: Span, fut: impl Future> + Send + 'static, ) -> JoinHandle<()> ``` ### Parameters - `_name` (&str): An unused name for the spawned task. - `span` (Span): The tracing span to associate with the future. - `fut` (impl Future> + Send + 'static): The future to spawn and execute. ### Returns - `JoinHandle<()>`: A handle to the spawned future, allowing for joining or cancellation. ``` -------------------------------- ### TorrentStorage::Take Method Source: https://docs.rs/librqbit/latest/librqbit/storage/trait.TorrentStorage.html Replaces the current storage with a dummy implementation and returns a new storage instance. This is used to invalidate the current storage, for example, when pausing a torrent. ```rust fn take(&self) -> Result> ``` -------------------------------- ### Getting Metadata with Error Handling Source: https://docs.rs/librqbit/latest/librqbit/api/type.Result.html Shows how to use `and_then` to chain operations that might fail, such as getting file metadata. This example handles potential errors like 'NotFound' when accessing file paths. ```rust use std::{io::ErrorKind, path::Path}; // Note: on Windows "/" maps to "C:\\" let root_modified_time = Path::new("/").metadata().and_then(|md| md.modified()); assert!(root_modified_time.is_ok()); let should_fail = Path::new("/bad/path").metadata().and_then(|md| md.modified()); assert!(should_fail.is_err()); assert_eq!(should_fail.unwrap_err().kind(), ErrorKind::NotFound); ``` -------------------------------- ### Check if Slice Starts With Prefix Source: https://docs.rs/librqbit/latest/librqbit/struct.ByteBufOwned.html Use `starts_with` to verify if a slice begins with a specified sequence of elements. An empty prefix always returns `true`. ```rust let v = [10, 40, 30]; assert!(v.starts_with(&[10])); assert!(v.starts_with(&[10, 40])); assert!(v.starts_with(&v)); assert!(!v.starts_with(&[50])); assert!(!v.starts_with(&[10, 50])); ``` ```rust let v = &[10, 40, 30]; assert!(v.starts_with(&[])); let v: &[u8] = &[]; assert!(v.starts_with(&[])); ``` -------------------------------- ### take Source: https://docs.rs/librqbit/latest/librqbit/storage/filesystem/struct.MmapFilesystemStorage.html Replaces the current storage with a dummy and returns a new storage instance. ```APIDOC ## take ### Description Replaces the current storage with a dummy storage and returns a new `TorrentStorage` instance that should be used subsequently. This is useful for disabling the underlying storage, for example, when pausing a torrent. ### Signature ```rust fn take(&self) -> Result> ``` ### Returns A `Result` containing a boxed dynamic trait object of `TorrentStorage`. ``` -------------------------------- ### Iterating Over Chunks from the End of a Slice Source: https://docs.rs/librqbit/latest/librqbit/struct.ByteBufOwned.html Use `rchunks` to get an iterator over slices of a specified `chunk_size`, starting from the end of the slice. The last chunk may be smaller if `chunk_size` does not evenly divide the slice length. Panics if `chunk_size` is zero. ```rust let slice = ['l', 'o', 'r', 'e', 'm']; let mut iter = slice.rchunks(2); assert_eq!(iter.next().unwrap(), &['e', 'm']); assert_eq!(iter.next().unwrap(), &['o', 'r']); assert_eq!(iter.next().unwrap(), &['l']); assert!(iter.next().is_none()); ``` -------------------------------- ### Get element offset using pointer arithmetic Source: https://docs.rs/librqbit/latest/librqbit/struct.ByteBufOwned.html Use `element_offset` to find the index of an element reference within a slice. This method uses pointer arithmetic and does not compare elements. It returns `None` if the element reference is not aligned to the start of an element. ```rust #![feature(substr_range)] let nums: &[u32] = &[1, 7, 1, 1]; let num = &nums[2]; assert_eq!(num, &1); assert_eq!(nums.element_offset(num), Some(2)); ``` ```rust #![feature(substr_range)] let arr: &[[u32; 2]] = &[[0, 1], [2, 3]]; let flat_arr: &[u32] = arr.as_flattened(); let ok_elm: &[u32; 2] = flat_arr[0..2].try_into().unwrap(); let weird_elm: &[u32; 2] = flat_arr[1..3].try_into().unwrap(); assert_eq!(ok_elm, &[0, 1]); assert_eq!(weird_elm, &[1, 2]); assert_eq!(arr.element_offset(ok_elm), Some(0)); // Points to element 0 assert_eq!(arr.element_offset(weird_elm), None); // Points between element 0 and 1 ``` -------------------------------- ### take Source: https://docs.rs/librqbit/latest/librqbit/storage/filesystem/struct.FilesystemStorage.html Replaces the current storage with a dummy instance and returns a new storage instance to be used instead. This is useful for operations like pausing a torrent. ```APIDOC ## fn take(&self) -> Result> ### Description Replace the current storage with a dummy, and return a new one that should be used instead. This is used to make the underlying object useless when e.g. pausing the torrent. ### Method `take` ### Returns - `Result>` - A boxed dynamic trait object representing the new storage instance. ``` -------------------------------- ### Get Raw Pointer Range of Slice Source: https://docs.rs/librqbit/latest/librqbit/struct.ByteBufOwned.html The `as_ptr_range` method returns a `Range` of two raw pointers representing the start and one-past-the-end of the slice's buffer. This is useful for interfacing with C-style APIs or checking pointer containment within the slice. ```rust let a = [1, 2, 3]; let x = &a[1] as *const _; let y = &5 as *const _; assert!(a.as_ptr_range().contains(&x)); assert!(!a.as_ptr_range().contains(&y)); ``` -------------------------------- ### Create Session with Options Source: https://docs.rs/librqbit/latest/librqbit/struct.Session.html Creates a new Session instance with custom options and a default output folder. ```rust pub fn new_with_opts( default_output_folder: PathBuf, opts: SessionOptions, ) -> BoxFuture<'static, Result>> ``` -------------------------------- ### get Source: https://docs.rs/librqbit/latest/librqbit/struct.ByteBufOwned.html Safely gets a reference to an element or subslice by index or range. ```APIDOC ## pub fn get(&self, index: I) -> Option<&>::Output> Returns a reference to an element or subslice. Returns `None` if the index is out of bounds. ``` -------------------------------- ### Get Slice Length Source: https://docs.rs/librqbit/latest/librqbit/struct.ByteBufOwned.html Use the `len` method to get the number of elements in a byte slice. This is a fundamental operation for understanding the size of the data. ```rust let a = [1, 2, 3]; assert_eq!(a.len(), 3); ``` -------------------------------- ### init Source: https://docs.rs/librqbit/latest/librqbit/storage/filesystem/struct.FilesystemStorage.html Initializes the storage with shared torrent data and metadata. ```APIDOC ## fn init(&mut self, shared: &ManagedTorrentShared, metadata: &TorrentMetadata) -> Result<()> ### Description Initializes the storage with shared torrent data and metadata. ### Method `init` ### Parameters #### Path Parameters - `shared` (&ManagedTorrentShared) - Required - Shared torrent data. - `metadata` (&TorrentMetadata) - Required - Torrent metadata. ``` -------------------------------- ### Get First Chunk of Slice as Array Source: https://docs.rs/librqbit/latest/librqbit/struct.ByteBufOwned.html Use `first_chunk::` to get a reference to the first `N` items of a slice as an array. Returns `None` if the slice is shorter than `N`. ```rust let u = [10, 40, 30]; assert_eq!(Some(&[10, 40]), u.first_chunk::<2>()); let v: &[i32] = &[10]; assert_eq!(None, v.first_chunk::<2>()); let w: &[i32] = &[]; assert_eq!(Some(&[]), w.first_chunk::<0>()); ``` -------------------------------- ### AddTorrent Methods Source: https://docs.rs/librqbit/latest/librqbit/enum.AddTorrent.html Provides methods for creating AddTorrent instances from command-line arguments, URLs, byte data, or local filenames, as well as converting an AddTorrent instance into bytes. ```APIDOC ## impl<'a> AddTorrent<'a> ### Methods * `from_cli_argument(path: &'a str) -> Result`: Creates an AddTorrent instance from a command-line argument path. * `from_url(url: impl Into>) -> Self`: Creates an AddTorrent instance from a URL. * `from_bytes(bytes: impl Into) -> Self`: Creates an AddTorrent instance from raw bytes. * `from_local_filename(filename: &str) -> Result`: Creates an AddTorrent instance from a local filename. * `into_bytes(self) -> Bytes`: Converts the AddTorrent instance into its byte representation. ``` -------------------------------- ### Safely Get Element or Subslice by Index Source: https://docs.rs/librqbit/latest/librqbit/struct.ByteBufOwned.html The `get` method provides safe access to slice elements or subslices using various index types (position or range). It returns `Some` on success and `None` if the index is out of bounds. ```rust let v = [10, 40, 30]; assert_eq!(Some(&40), v.get(1)); assert_eq!(Some(&[10, 40][..]), v.get(0..2)); assert_eq!(None, v.get(3)); assert_eq!(None, v.get(0..4)); ``` -------------------------------- ### Limits::prepare_for_download Source: https://docs.rs/librqbit/latest/librqbit/limits/struct.Limits.html Asynchronously prepares the limits for a download operation of a given length. ```APIDOC ## Limits::prepare_for_download ### Description Asynchronously prepares the limits for a download operation of a given length. ### Signature ```rust pub async fn prepare_for_download(&self, len: NonZeroU32) -> Result<()> ``` ``` -------------------------------- ### HttpApiClient::new Source: https://docs.rs/librqbit/latest/librqbit/http_api_client/struct.HttpApiClient.html Creates a new HttpApiClient instance. Requires the base URL of the qBittorrent Web API. ```rust pub fn new(url: &str) -> Result ``` -------------------------------- ### Any for T Source: https://docs.rs/librqbit/latest/librqbit/struct.ByteBufOwned.html Provides the `type_id` method to get the `TypeId` of the instance. ```APIDOC ## fn type_id(&self) -> TypeId Gets the `TypeId` of `self`. ``` -------------------------------- ### Get ByteBuf Length Source: https://docs.rs/librqbit/latest/librqbit/struct.ByteBuf.html Returns the number of bytes in the ByteBuf. ```rust pub fn len(&self) -> usize ``` ```rust let a = [1, 2, 3]; assert_eq!(a.len(), 3); ``` -------------------------------- ### StorageFactory create_and_init Method Source: https://docs.rs/librqbit/latest/librqbit/storage/trait.StorageFactory.html Provided method to create and initialize a TorrentStorage instance. This is a convenience method that calls `create` and performs initialization. ```rust fn create_and_init( &self, shared: &ManagedTorrentShared, metadata: &TorrentMetadata, ) -> Result { ... } ``` -------------------------------- ### TorrentStorage::Init Method Source: https://docs.rs/librqbit/latest/librqbit/storage/trait.TorrentStorage.html Initializes the storage with shared torrent data and metadata. This method is called once when the torrent is loaded. ```rust fn init( &mut self, shared: &ManagedTorrentShared, metadata: &TorrentMetadata, ) -> Result<()> ``` -------------------------------- ### Get Cancellation Token Source: https://docs.rs/librqbit/latest/librqbit/struct.Session.html Retrieves the cancellation token for the session. ```rust pub fn cancellation_token(&self) -> &CancellationToken ``` -------------------------------- ### Default Implementation for CreateTorrentOptions Source: https://docs.rs/librqbit/latest/librqbit/struct.CreateTorrentOptions.html Provides a default value for CreateTorrentOptions, useful for initialization. ```rust fn default() -> CreateTorrentOptions<'a> ``` -------------------------------- ### Get ApiError Status Code Source: https://docs.rs/librqbit/latest/librqbit/struct.ApiError.html Returns the StatusCode associated with this ApiError. ```rust pub fn status(&self) -> StatusCode ``` -------------------------------- ### Version Source: https://docs.rs/librqbit/latest/librqbit/all.html Returns the version of the librqbit library. ```APIDOC ## version ### Description Returns the version string of the librqbit library. ### Returns - `&'static str`: The version string. ``` -------------------------------- ### iter Source: https://docs.rs/librqbit/latest/librqbit/struct.ByteBuf.html Returns an iterator over the slice, yielding all items from start to end. ```APIDOC ## pub fn iter(&self) -> Iter<'_, T> ### Description Returns an iterator over the slice. The iterator yields all items from start to end. ### Returns An iterator over the elements of the slice. ``` -------------------------------- ### as_array Source: https://docs.rs/librqbit/latest/librqbit/struct.ByteBufOwned.html Attempts to get a reference to the underlying array if the length matches `N`. ```APIDOC ## pub fn as_array(&self) -> Option<&[T; N]> Returns a reference to the underlying array if `N` is equal to the slice's length. This is a nightly-only experimental API. ``` -------------------------------- ### Create New Session Source: https://docs.rs/librqbit/latest/librqbit/struct.Session.html Initializes a new Session with a default output folder. This method runs a DHT server/client and a TCP listener. ```rust pub fn new( default_output_folder: PathBuf, ) -> BoxFuture<'static, Result>> ``` -------------------------------- ### HttpApiClient::new Source: https://docs.rs/librqbit/latest/librqbit/http_api_client/struct.HttpApiClient.html Creates a new HttpApiClient instance. It requires the base URL of the rqbit server. ```APIDOC ## HttpApiClient::new ### Description Creates a new `HttpApiClient` instance. ### Method `pub fn new(url: &str) -> Result` ### Parameters #### Path Parameters - **url** (str) - Required - The base URL of the rqbit server. ``` -------------------------------- ### get_unchecked Source: https://docs.rs/librqbit/latest/librqbit/struct.ByteBufOwned.html Unsafely gets a reference to an element or subslice without bounds checking. ```APIDOC ## pub unsafe fn get_unchecked( &self, index: I, ) -> &>::Output Returns a reference to an element or subslice without bounds checking. Use with caution as out-of-bounds access is undefined behavior. ``` -------------------------------- ### Session::new Source: https://docs.rs/librqbit/latest/librqbit/struct.Session.html Creates a new session with default options. The provided folder is used as a default output location for torrents. ```APIDOC ## Session::new ### Description Creates a new session with default options. The passed in folder will be used as a default unless overriden per torrent. It will run a DHT server/client, a TCP listener and . ### Signature ```rust pub fn new( default_output_folder: PathBuf, ) -> BoxFuture<'static, Result>> ``` ### Parameters * `default_output_folder` (PathBuf) - The default output folder for torrents. ``` -------------------------------- ### Get Session Stats Snapshot Source: https://docs.rs/librqbit/latest/librqbit/struct.Session.html Returns a snapshot of the session's statistics. ```rust pub fn stats_snapshot(&self) -> SessionStatsSnapshot ``` -------------------------------- ### Get librqbit Version Source: https://docs.rs/librqbit/latest/librqbit/fn.version.html Returns the cargo version of librqbit. This is a constant function. ```rust pub const fn version() -> &'static str ``` -------------------------------- ### FilesystemStorageFactory::create_and_init Source: https://docs.rs/librqbit/latest/librqbit/storage/filesystem/struct.FilesystemStorageFactory.html Creates and initializes a new FilesystemStorage instance. This method is part of the StorageFactory trait implementation for FilesystemStorageFactory. ```APIDOC ## FilesystemStorageFactory::create_and_init ### Description Creates and initializes a new FilesystemStorage instance. ### Method Signature `fn create_and_init(&self, shared: &ManagedTorrentShared, metadata: &TorrentMetadata) -> Result` ### Parameters - `shared`: A reference to `ManagedTorrentShared`. - `metadata`: A reference to `TorrentMetadata`. ### Returns A `Result` containing the initialized storage instance (`Self::Storage`) on success, or an error on failure. ``` -------------------------------- ### Api::torrent_file_mime_type Source: https://docs.rs/librqbit/latest/librqbit/api/struct.Api.html Gets the MIME type of a specific file within a torrent. ```APIDOC ## Api::torrent_file_mime_type ### Description Gets the MIME type of a specific file within a torrent. ### Signature `pub fn torrent_file_mime_type(&self, idx: TorrentIdOrHash, file_idx: usize) -> Result<&'static str>` ``` -------------------------------- ### Clone Implementation for CreateTorrentOptions Source: https://docs.rs/librqbit/latest/librqbit/struct.CreateTorrentOptions.html Provides methods to duplicate CreateTorrentOptions instances. ```rust fn clone(&self) -> CreateTorrentOptions<'a> ``` ```rust fn clone_from(&mut self, source: &Self) ``` -------------------------------- ### rchunks_exact Source: https://docs.rs/librqbit/latest/librqbit/struct.ByteBufOwned.html Returns an iterator over chunks of a specified size, starting from the end, with no remainder. ```APIDOC ## pub fn rchunks_exact(&self, chunk_size: usize) -> RChunksExact<'_, T> ### Description Returns an iterator over `chunk_size` elements of the slice at a time, starting at the end of the slice. The chunks are slices and do not overlap. If `chunk_size` does not divide the length of the slice, then the last up to `chunk_size-1` elements will be omitted. ### Parameters - `chunk_size`: The desired exact size of each chunk. ### Returns An iterator yielding slices of exactly `chunk_size` elements. ### Panics Panics if `chunk_size` is zero. ### Examples ``` let slice = ['l', 'o', 'r', 'e', 'm']; let mut iter = slice.rchunks_exact(2); assert_eq!(iter.next().unwrap(), &['e', 'm']); assert_eq!(iter.next().unwrap(), &['o', 'r']); assert!(iter.next().is_none()); // The remainder can be obtained from the iterator itself if needed. ``` ``` -------------------------------- ### Session::new_with_opts Source: https://docs.rs/librqbit/latest/librqbit/struct.Session.html Creates a new session with custom options. ```APIDOC ## Session::new_with_opts ### Description Creates a new session with options. ### Signature ```rust pub fn new_with_opts( default_output_folder: PathBuf, opts: SessionOptions, ) -> BoxFuture<'static, Result>> ``` ### Parameters * `default_output_folder` (PathBuf) - The default output folder for torrents. * `opts` (SessionOptions) - The session options to use. ``` -------------------------------- ### Display Implementation Source: https://docs.rs/librqbit/latest/librqbit/struct.ByteBuf.html Allows ByteBuf instances to be formatted for display. ```APIDOC ## fmt (Display) ### Description Formats the value using the given formatter. ### Signature fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> ``` -------------------------------- ### rchunks Source: https://docs.rs/librqbit/latest/librqbit/struct.ByteBufOwned.html Returns an iterator over chunks of a specified size, starting from the end of the slice. ```APIDOC ## pub fn rchunks(&self, chunk_size: usize) -> RChunks<'_, T> ### Description Returns an iterator over `chunk_size` elements of the slice at a time, starting at the end of the slice. The chunks are slices and do not overlap. ### Parameters - `chunk_size`: The desired size of each chunk. ### Returns An iterator yielding slices of `chunk_size` elements. ### Panics Panics if `chunk_size` is zero. ### Examples ``` let slice = ['l', 'o', 'r', 'e', 'm']; let mut iter = slice.rchunks(2); assert_eq!(iter.next().unwrap(), &['e', 'm']); assert_eq!(iter.next().unwrap(), &['o', 'r']); assert_eq!(iter.next().unwrap(), &['l']); assert!(iter.next().is_none()); ``` ``` -------------------------------- ### Get TCP Listen Port Source: https://docs.rs/librqbit/latest/librqbit/struct.Session.html Retrieves the TCP listen port configured for the session, if any. ```rust pub fn tcp_listen_port(&self) -> Option ``` -------------------------------- ### client_name_and_version Source: https://docs.rs/librqbit/latest/librqbit/fn.client_name_and_version.html Returns the client's name and version as a static string. ```APIDOC ## client_name_and_version ### Description Returns the client's name and version as a static string. ### Signature ```rust pub const fn client_name_and_version() -> &'static str ``` ``` -------------------------------- ### clone_to_uninit Source: https://docs.rs/librqbit/latest/librqbit/struct.TorrentMetaV1Info.html This is a nightly-only experimental API. Performs copy-assignment from `self` to `dest`. ```APIDOC ## unsafe fn clone_to_uninit(&self, dest: *mut u8) ### Description Performs copy-assignment from `self` to `dest`. ### Method `unsafe fn` ### Parameters - `dest` (*mut u8) - Description: Pointer to the destination buffer. ``` -------------------------------- ### Get DHT Server/Client Source: https://docs.rs/librqbit/latest/librqbit/struct.Session.html Retrieves an optional reference to the DHT server/client associated with the session. ```rust pub fn get_dht(&self) -> Option<&Dht> ``` -------------------------------- ### librqbit Spawn Source: https://docs.rs/librqbit/latest/librqbit/all.html Spawns a new asynchronous task using the librqbit runtime. ```APIDOC ## librqbit_spawn ### Description Spawns a new asynchronous task within the librqbit runtime. ### Parameters - `future`: The future to be spawned. ### Type Parameters - `F`: The type of the future, which must implement `Future` and `Send`. ``` -------------------------------- ### Get Select Only Fields Source: https://docs.rs/librqbit/latest/librqbit/struct.Magnet.html Retrieves the optional list of indices for selective downloading, if specified. ```rust pub fn get_select_only(&self) -> Option> ``` -------------------------------- ### Get Magnet ID as Id32 Source: https://docs.rs/librqbit/latest/librqbit/struct.Magnet.html Retrieves the 32-byte identifier of the magnet link, if available. ```rust pub fn as_id32(&self) -> Option> ``` -------------------------------- ### Api::new Source: https://docs.rs/librqbit/latest/librqbit/api/struct.Api.html Constructs a new Api instance with the provided session and an optional log reload sender. ```APIDOC ## Api::new ### Description Constructs a new Api instance with the provided session and an optional log reload sender. ### Signature `pub fn new(session: Arc, rust_log_reload_tx: Option>) -> Self` ``` -------------------------------- ### Get Magnet ID as Id20 Source: https://docs.rs/librqbit/latest/librqbit/struct.Magnet.html Retrieves the 20-byte identifier of the magnet link, if available. ```rust pub fn as_id20(&self) -> Option> ``` -------------------------------- ### Display Implementation Source: https://docs.rs/librqbit/latest/librqbit/struct.ByteBufOwned.html Allows formatting the ByteBufOwned for display purposes, typically as a string. ```APIDOC ## impl Display for ByteBufOwned ### fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> #### Description Formats the value using the given formatter for display output. This is often used for user-facing string representations. ``` -------------------------------- ### pieces_usize Implementation for FileDetailsExt Source: https://docs.rs/librqbit/latest/librqbit/struct.FileDetailsExt.html Provides a method to get the pieces range as usize for FileDetailsExt. ```rust pub fn pieces_usize(&self) -> Range ``` -------------------------------- ### StorageFactory create Method Source: https://docs.rs/librqbit/latest/librqbit/storage/trait.StorageFactory.html Required method to create a new TorrentStorage instance. Use this when you need to instantiate storage for a torrent. ```rust fn create( &self, shared: &ManagedTorrentShared, metadata: &TorrentMetadata, ) -> Result ``` -------------------------------- ### as_rchunks Source: https://docs.rs/librqbit/latest/librqbit/struct.ByteBufOwned.html Splits the slice into a remainder slice and a slice of N-element arrays, starting from the end. ```APIDOC ## pub fn as_rchunks(&self) -> (&[T], &[[T; N]]) ### Description Splits the slice into a slice of `N`-element arrays, starting at the end of the slice, and a remainder slice with length strictly less than `N`. ### Parameters - `N`: const generic parameter specifying the size of each chunk array. ### Returns A tuple containing: - A remainder slice (`&[T]`) with length strictly less than `N`. - A slice of `N`-element arrays (`&[[T; N]]`). ### Panics Panics if `N` is zero. ### Examples ``` let slice = ['l', 'o', 'r', 'e', 'm']; let (remainder, chunks) = slice.as_rchunks::<2>(); assert_eq!(remainder, &['l']); assert_eq!(chunks, &[['o', 'r'], ['e', 'm']]); ``` ``` -------------------------------- ### PartialEq Implementation for TorrentMetaV1File Source: https://docs.rs/librqbit/latest/librqbit/struct.TorrentMetaV1File.html Provides equality comparison for `TorrentMetaV1File` instances if `BufType` supports `PartialEq`. This allows checking if two file entries are identical. ```rust fn eq(&self, other: &TorrentMetaV1File) -> bool Tests for `self` and `other` values to be equal, and is used by `==`. ``` ```rust fn ne(&self, other: &Rhs) -> bool Tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. ``` -------------------------------- ### Get Managed Torrent by ID Source: https://docs.rs/librqbit/latest/librqbit/struct.Session.html Retrieves an optional reference to a managed torrent by its ID or hash. ```rust pub fn get(&self, id: TorrentIdOrHash) -> Option> ``` -------------------------------- ### Limits::new Source: https://docs.rs/librqbit/latest/librqbit/limits/struct.Limits.html Constructs a new Limits instance with the provided configuration. ```APIDOC ## Limits::new ### Description Constructs a new `Limits` instance with the provided configuration. ### Signature ```rust pub fn new(config: LimitsConfig) -> Self ``` ``` -------------------------------- ### Get Torrent Name Source: https://docs.rs/librqbit/latest/librqbit/struct.ManagedTorrent.html Retrieves the optional name of the managed torrent. Returns None if the name is not available. ```rust pub fn name(&self) -> Option ``` -------------------------------- ### trim_prefix Source: https://docs.rs/librqbit/latest/librqbit/struct.ByteBufOwned.html Returns a subslice with the optional prefix removed. If the slice does not start with the prefix, the original slice is returned. ```APIDOC ## pub fn trim_prefix

(&self, prefix: &P) -> &[T] where P: SlicePattern + ?Sized, T: PartialEq, Returns a subslice with the optional prefix removed. If the slice starts with `prefix`, returns the subslice after the prefix. If `prefix` is empty or the slice does not start with `prefix`, simply returns the original slice. If `prefix` is equal to the original slice, returns an empty slice. ``` -------------------------------- ### FmtForward::fmt_list Source: https://docs.rs/librqbit/latest/librqbit/http_api_client/struct.HttpApiClient.html Formats each item in a sequence using the HttpApiClient. ```rust fn fmt_list(self) -> FmtList where &'a Self: for<'a> IntoIterator ``` -------------------------------- ### or Source: https://docs.rs/librqbit/latest/librqbit/enum.FileIteratorName.html Creates a new Policy that returns Action::Follow if either self or the other policy return Action::Follow. ```APIDOC ## or ### Description Create a new `Policy` that returns `Action::Follow` if either `self` or `other` returns `Action::Follow`. ### Method `or(self, other: P) -> Or` ### Type Parameters - `P`: The type of the other policy. - `B`: The type of the context. - `E`: The type of the error. ### Trait Bounds - `T: Policy` - `P: Policy` ``` -------------------------------- ### strip_prefix Source: https://docs.rs/librqbit/latest/librqbit/struct.ByteBufOwned.html Returns a subslice with the prefix removed if the slice starts with the given prefix. Returns None otherwise. ```APIDOC ## pub fn strip_prefix

(&self, prefix: &P) -> Option<&[T]> where P: SlicePattern + ?Sized, T: PartialEq, Returns a subslice with the prefix removed. If the slice starts with `prefix`, returns the subslice after the prefix, wrapped in `Some`. If `prefix` is empty, simply returns the original slice. If `prefix` is equal to the original slice, returns an empty slice. If the slice does not start with `prefix`, returns `None`. ### Examples ```rust let v = &[10, 40, 30]; assert_eq!(v.strip_prefix(&[10]), Some(&[40, 30][..])); assert_eq!(v.strip_prefix(&[10, 40]), Some(&[30][..])); assert_eq!(v.strip_prefix(&[10, 40, 30]), Some(&[][..])); assert_eq!(v.strip_prefix(&[50]), None); assert_eq!(v.strip_prefix(&[10, 50]), None); let prefix : &str = "he"; assert_eq!(b"hello".strip_prefix(prefix.as_bytes()), Some(b"llo".as_ref())); ``` ``` -------------------------------- ### FileInfo Implementations Source: https://docs.rs/librqbit/latest/librqbit/file_info/struct.FileInfo.html Shows available implementations for the FileInfo struct. ```rust impl FileInfo ``` -------------------------------- ### as_array Source: https://docs.rs/librqbit/latest/librqbit/struct.ByteBuf.html Attempts to get a reference to the underlying array if its length exactly matches `N`. This is a nightly-only experimental API. ```APIDOC ## pub fn as_array(&self) -> Option<&[T; N]> ### Description Gets a reference to the underlying array. If `N` is not exactly equal to the length of `self`, then this method returns `None`. This is a nightly-only experimental API. ### Parameters * `N`: The expected length of the array. ### Returns An `Option` containing a reference to the underlying array if its length matches `N`, otherwise `None`. ``` -------------------------------- ### Get Last Element of ByteBuf Source: https://docs.rs/librqbit/latest/librqbit/struct.ByteBuf.html Returns an Option containing a reference to the last byte, or None if the ByteBuf is empty. ```rust pub fn last(&self) -> Option<&T> ``` ```rust let v = [10, 40, 30]; assert_eq!(Some(&30), v.last()); let w: &[i32] = &[]; assert_eq!(None, w.last()); ``` -------------------------------- ### Serialize Implementation for AddTorrentOptions Source: https://docs.rs/librqbit/latest/librqbit/struct.AddTorrentOptions.html Enables serialization of AddTorrentOptions to a Serde serializer. Use this when saving or transmitting torrent options. ```rust fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where __S: Serializer, ``` -------------------------------- ### Get First Element of ByteBuf Source: https://docs.rs/librqbit/latest/librqbit/struct.ByteBuf.html Returns an Option containing a reference to the first byte, or None if the ByteBuf is empty. ```rust pub fn first(&self) -> Option<&T> ``` ```rust let v = [10, 40, 30]; assert_eq!(Some(&10), v.first()); let w: &[i32] = &[]; assert_eq!(None, w.first()); ``` -------------------------------- ### Default Implementation for FilesystemStorageFactory Source: https://docs.rs/librqbit/latest/librqbit/storage/filesystem/struct.FilesystemStorageFactory.html Enables creating a default instance of FilesystemStorageFactory. ```rust fn default() -> FilesystemStorageFactory ``` -------------------------------- ### Result Unwrap Panic Example Source: https://docs.rs/librqbit/latest/librqbit/api/type.Result.html Shows how `unwrap` panics when called on an `Err` variant, displaying the error message. ```rust let x: Result = Err("emergency failure"); x.unwrap(); // panics with `emergency failure` ``` -------------------------------- ### starts_with Source: https://docs.rs/librqbit/latest/librqbit/struct.ByteBuf.html Determines if the slice begins with a specified prefix slice. ```APIDOC ## starts_with(&self, needle: &[T]) -> bool ### Description Returns `true` if `needle` is a prefix of the slice or equal to the slice. ### Method `starts_with` ### Parameters - `needle`: The slice to check as a prefix. ### Returns - `bool`: `true` if the slice starts with `needle`, `false` otherwise. ### Example ```rust let v = [10, 40, 30]; assert!(v.starts_with(&[10])); assert!(v.starts_with(&[10, 40])); assert!(v.starts_with(&v)); assert!(!v.starts_with(&[50])); assert!(!v.starts_with(&[10, 50])); ``` ``` -------------------------------- ### IntoAddTorrentOptions Implementation Source: https://docs.rs/librqbit/latest/librqbit/http_api_types/struct.TorrentAddQueryParams.html Converts a TorrentAddQueryParams instance into AddTorrentOptions, likely for internal processing. ```rust pub fn into_add_torrent_options(self) -> AddTorrentOptions ``` -------------------------------- ### element_offset Source: https://docs.rs/librqbit/latest/librqbit/struct.ByteBufOwned.html Returns the index that an element reference points to, if it points to the start of an element within the slice. This is an experimental nightly-only API. ```APIDOC ## pub fn element_offset(&self, element: &T) -> Option ### Description Returns the index that an element reference points to. Returns `None` if `element` does not point to the start of an element within the slice. This method is useful for extending slice iterators like `slice::split`. Note that this uses pointer arithmetic and **does not compare elements**. To find the index of an element via comparison, use `.iter().position()` instead. ### Parameters * `element` - A reference to the element whose offset is to be found. ### Returns `Option` - `Some(index)` if the element reference points to the start of an element, `None` otherwise. ### Panics Panics if `T` is zero-sized. ### Examples ```rust #![feature(substr_range)] let nums: &[u32] = &[1, 7, 1, 1]; let num = &nums[2]; assert_eq!(num, &1); assert_eq!(nums.element_offset(num), Some(2)); let arr: &[[u32; 2]] = &[[0, 1], [2, 3]]; let flat_arr: &[u32] = arr.as_flattened(); let ok_elm: &[u32; 2] = flat_arr[0..2].try_into().unwrap(); let weird_elm: &[u32; 2] = flat_arr[1..3].try_into().unwrap(); assert_eq!(ok_elm, &[0, 1]); assert_eq!(weird_elm, &[1, 2]); assert_eq!(arr.element_offset(ok_elm), Some(0)); // Points to element 0 assert_eq!(arr.element_offset(weird_elm), None); // Points between element 0 and 1 ``` ``` -------------------------------- ### Serialize Implementation Source: https://docs.rs/librqbit/latest/librqbit/api/struct.TorrentDetailsResponseFile.html Provides the implementation for serializing a TorrentDetailsResponseFile into a Serde serializer. ```APIDOC ### impl Serialize for TorrentDetailsResponseFile #### fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> Serialize this value into the given Serde serializer. ``` -------------------------------- ### TryInto::try_into Source: https://docs.rs/librqbit/latest/librqbit/api/enum.TorrentIdOrHash.html Performs the conversion. ```APIDOC ## fn try_into(self) -> Result>::Error> where U: TryFrom, Performs the conversion. ``` -------------------------------- ### Create Torrent Source: https://docs.rs/librqbit/latest/librqbit/all.html Creates a torrent file from specified options. ```APIDOC ## create_torrent ### Description Creates a torrent file based on the provided options. ### Parameters - `options` (CreateTorrentOptions): Options for creating the torrent. ### Returns - `Result`: A Result containing the created torrent metadata or an ApiError. ``` -------------------------------- ### Get Torrent ID Source: https://docs.rs/librqbit/latest/librqbit/struct.ManagedTorrent.html Retrieves the unique identifier for the managed torrent. This is useful for tracking or referencing specific torrents within the system. ```rust pub fn id(&self) -> usize ``` -------------------------------- ### Get Name of ManagedTorrentState Source: https://docs.rs/librqbit/latest/librqbit/enum.ManagedTorrentState.html Retrieves a static string slice representing the name of the current ManagedTorrentState. This is useful for logging or display purposes. ```rust pub fn name(&self) -> &'static str ``` -------------------------------- ### Implementations of CloneToOwned Source: https://docs.rs/librqbit/latest/librqbit/trait.CloneToOwned.html Demonstrates various implementations of the `CloneToOwned` trait for different types, showcasing how owned versions are created. ```APIDOC ### impl CloneToOwned for u8 #### type Target = u8 #### fn clone_to_owned( &self, _within_buffer: Option<&Bytes>, ) -> ::Target ### impl CloneToOwned for u32 #### type Target = u32 #### fn clone_to_owned( &self, _within_buffer: Option<&Bytes>, ) -> ::Target ### impl CloneToOwned for UtPex where B: CloneToOwned, #### type Target = UtPex<::Target> #### fn clone_to_owned( &self, within_buffer: Option<&Bytes>, ) -> as CloneToOwned>::Target ### impl CloneToOwned for Handshake where B: CloneToOwned, #### type Target = Handshake<::Target> #### fn clone_to_owned( &self, within_buffer: Option<&Bytes>, ) -> as CloneToOwned>::Target ### impl CloneToOwned for Piece where B: CloneToOwned, #### type Target = Piece<::Target> #### fn clone_to_owned( &self, within_buffer: Option<&Bytes>, ) -> as CloneToOwned>::Target ### impl CloneToOwned for BencodeValue where BufT: CloneToOwned + Hash + Eq, ::Target: Eq + Hash, #### type Target = BencodeValue<::Target> #### fn clone_to_owned( &self, within_buffer: Option<&Bytes>, ) -> as CloneToOwned>::Target ### impl CloneToOwned for Message where ByteBuf: ByteBufT, ::Target: ByteBufT, #### type Target = Message<::Target> #### fn clone_to_owned( &self, within_buffer: Option<&Bytes>, ) -> as CloneToOwned>::Target ### impl CloneToOwned for ExtendedMessage where ByteBuf: ByteBufT, ::Target: ByteBufT, #### type Target = ExtendedMessage<::Target> #### fn clone_to_owned( &self, within_buffer: Option<&Bytes>, ) -> as CloneToOwned>::Target ### impl CloneToOwned for UtMetadata where ByteBuf: CloneToOwned, #### type Target = UtMetadata<::Target> #### fn clone_to_owned( &self, within_buffer: Option<&Bytes>, ) -> as CloneToOwned>::Target ### impl CloneToOwned for ExtendedHandshake where ByteBuf: ByteBufT, ::Target: ByteBufT, #### type Target = ExtendedHandshake<::Target> #### fn clone_to_owned( &self, within_buffer: Option<&Bytes>, ) -> as CloneToOwned>::Target ### impl CloneToOwned for HashMap where K: CloneToOwned, ::Target: Hash + Eq, V: CloneToOwned, #### type Target = HashMap<::Target, ::Target> #### fn clone_to_owned( &self, within_buffer: Option<&Bytes>, ) -> as CloneToOwned>::Target ### impl CloneToOwned for Option where T: CloneToOwned, #### type Target = Option<::Target> #### fn clone_to_owned( &self, within_buffer: Option<&Bytes>, ) -> as CloneToOwned>::Target ### impl CloneToOwned for Vec where T: CloneToOwned, #### type Target = Vec<::Target> #### fn clone_to_owned( &self, within_buffer: Option<&Bytes>, ) -> as CloneToOwned>::Target ### impl CloneToOwned for ByteBuf<'_> #### type Target = ByteBufOwned ### impl CloneToOwned for ByteBufOwned #### type Target = ByteBufOwned ### impl CloneToOwned for TorrentMetaV1 where BufType: CloneToOwned, #### type Target = TorrentMetaV1<::Target> ### impl CloneToOwned for TorrentMetaV1File where BufType: CloneToOwned, #### type Target = TorrentMetaV1File<::Target> ### impl CloneToOwned for TorrentMetaV1Info where BufType: CloneToOwned, #### type Target = TorrentMetaV1Info<::Target> ``` -------------------------------- ### rchunks_exact Source: https://docs.rs/librqbit/latest/librqbit/struct.ByteBuf.html Returns an iterator over chunks of a specified size, starting from the end. All chunks except possibly the remainder will have the exact specified size. ```APIDOC ## pub fn rchunks_exact(&self, chunk_size: usize) -> RChunksExact<'_, T> ### Description Returns an iterator over `chunk_size` elements of the slice at a time, starting at the end of the slice. The chunks are slices and do not overlap. If `chunk_size` does not divide the length of the slice, then the last up to `chunk_size-1` elements will be omitted and can be retrieved from the `remainder` function of the iterator. ### Parameters - `chunk_size`: The desired exact size of each chunk. ### Returns An iterator yielding slices of exactly `chunk_size` elements, and a method to access the remainder. ### Panics Panics if `chunk_size` is zero. ### Examples ``` let slice = ['l', 'o', 'r', 'e', 'm']; let mut iter = slice.rchunks_exact(2); assert_eq!(iter.next().unwrap(), &['o', 'r']); assert_eq!(iter.next().unwrap(), &['e', 'm']); assert_eq!(iter.remainder(), &['l']); ``` ``` -------------------------------- ### Serialize Implementation for TorrentMetaV1File Source: https://docs.rs/librqbit/latest/librqbit/struct.TorrentMetaV1File.html Enables serializing `TorrentMetaV1File` into a Serde serializer, provided `BufType` also implements `Serialize`. This is necessary for writing torrent metadata to various formats. ```rust fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where __S: Serializer, Serialize this value into the given Serde serializer. Read more ``` -------------------------------- ### fn vzip(self) -> V Source: https://docs.rs/librqbit/latest/librqbit/api/struct.Api.html None ```APIDOC ## fn vzip(self) -> V ### Description None ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### Serialize Implementation Source: https://docs.rs/librqbit/latest/librqbit/struct.ByteBufOwned.html Allows serializing ByteBufOwned into various data formats using Serde. ```APIDOC ## impl Serialize for ByteBufOwned ### fn serialize( &self, serializer: S, ) -> Result<::Ok, ::Error> where S: Serializer, #### Description Serialize this `ByteBufOwned` value into the given Serde serializer. This enables `ByteBufOwned` to be converted into formats like JSON, Bincode, etc. ``` -------------------------------- ### Get First Chunk of ByteBuf Source: https://docs.rs/librqbit/latest/librqbit/struct.ByteBuf.html Returns an array reference to the first N items in the slice. Returns None if the slice is shorter than N. ```rust pub fn first_chunk(&self) -> Option<&[T; N]> ``` ```rust let u = [10, 40, 30]; assert_eq!(Some(&[10, 40]), u.first_chunk::<2>()); let v: &[i32] = &[10]; assert_eq!(None, v.first_chunk::<2>()); let w: &[i32] = &[]; assert_eq!(Some(&[]), w.first_chunk::<0>()); ``` -------------------------------- ### Get Live Torrent State Source: https://docs.rs/librqbit/latest/librqbit/struct.ManagedTorrent.html Retrieves the live state of the torrent if it is currently active and streaming. Returns None if the torrent is not in a live state. ```rust pub fn live(&self) -> Option> ``` -------------------------------- ### TryFrom::try_from Source: https://docs.rs/librqbit/latest/librqbit/api/enum.TorrentIdOrHash.html Performs the conversion. ```APIDOC ## fn try_from(value: U) -> Result>::Error> where U: Into, Performs the conversion. ``` -------------------------------- ### Unwrap or Default for Result Source: https://docs.rs/librqbit/latest/librqbit/api/type.Result.html Uses `unwrap_or_default` to get the contained value or a default if the `Result` is `Err`. This is useful for fallbacks when parsing or converting types. ```rust let good_year_from_input = "1909"; let bad_year_from_input = "190blarg"; let good_year = good_year_from_input.parse().unwrap_or_default(); let bad_year = bad_year_from_input.parse().unwrap_or_default(); assert_eq!(1909, good_year); assert_eq!(0, bad_year); ``` -------------------------------- ### default_json_persistence_folder() Source: https://docs.rs/librqbit/latest/librqbit/enum.SessionPersistenceConfig.html A function to get the default folder path for JSON persistence. This is useful for setting up session persistence without manually specifying a directory. ```APIDOC ## impl SessionPersistenceConfig ### pub fn default_json_persistence_folder() -> Result Gets the default folder path for JSON persistence. ``` -------------------------------- ### TryInto Implementation Source: https://docs.rs/librqbit/latest/librqbit/enum.AddTorrentResponse.html Implementation of `TryInto` for type conversions. ```APIDOC #### type Error = >::Error ### Description The type returned in the event of a conversion error. ```