librqbit/
lib.rs

1//!
2//! This crate provides everything necessary to download [torrents](https://en.wikipedia.org/wiki/BitTorrent).
3//!
4//! # Quick usage example
5//!
6//! ```no_run
7//! use librqbit::*;
8//!
9//! tokio_test::block_on(async {
10//!     let session = Session::new("/tmp/where-to-download".into()).await.unwrap();
11//!     let managed_torrent_handle = session.add_torrent(
12//!        AddTorrent::from_url("magnet:?xt=urn:btih:cab507494d02ebb1178b38f2e9d7be299c86b862"),
13//!        None // options
14//!     ).await.unwrap().into_handle().unwrap();
15//!     managed_torrent_handle.wait_until_completed().await.unwrap();
16//! })
17//! ```
18//!
19//! # Overview
20//! The main type to start off with is [`Session`].
21//!
22//! It also proved useful to use the [`Api`] when building the rqbit desktop app, as it provides
23//! a facade that works with simple serializable types.
24//!
25
26#![warn(clippy::cast_possible_truncation)]
27
28macro_rules! aframe {
29    ($e:expr) => {{
30        #[cfg(feature = "async-bt")]
31        {
32            async_backtrace::frame!($e)
33        }
34        #[cfg(not(feature = "async-bt"))]
35        {
36            $e
37        }
38    }};
39}
40
41pub mod api;
42mod api_error;
43mod bitv;
44mod bitv_factory;
45mod blocklist;
46mod chunk_tracker;
47mod create_torrent_file;
48mod dht_utils;
49pub mod file_info;
50mod file_ops;
51#[cfg(feature = "http-api")]
52pub mod http_api;
53#[cfg(feature = "http-api-client")]
54pub mod http_api_client;
55#[cfg(any(feature = "http-api", feature = "http-api-client"))]
56pub mod http_api_types;
57pub mod limits;
58mod merge_streams;
59mod peer_connection;
60mod peer_info_reader;
61mod read_buf;
62mod session;
63mod session_persistence;
64pub mod session_stats;
65mod spawn_utils;
66pub mod storage;
67mod stream_connect;
68mod torrent_state;
69#[cfg(feature = "tracing-subscriber-utils")]
70pub mod tracing_subscriber_config_utils;
71mod type_aliases;
72#[cfg(all(feature = "http-api", feature = "upnp-serve-adapter"))]
73pub mod upnp_server_adapter;
74#[cfg(feature = "watch")]
75pub mod watch;
76
77pub use api::Api;
78pub use api_error::ApiError;
79pub use create_torrent_file::{create_torrent, CreateTorrentOptions};
80pub use dht;
81pub use peer_connection::PeerConnectionOptions;
82pub use session::{
83    AddTorrent, AddTorrentOptions, AddTorrentResponse, ListOnlyResponse, Session, SessionOptions,
84    SessionPersistenceConfig, SUPPORTED_SCHEMES,
85};
86pub use spawn_utils::spawn as librqbit_spawn;
87pub use torrent_state::{
88    ManagedTorrent, ManagedTorrentShared, ManagedTorrentState, TorrentMetadata, TorrentStats,
89    TorrentStatsState,
90};
91pub use type_aliases::FileInfos;
92
93pub use buffers::*;
94pub use clone_to_owned::CloneToOwned;
95pub use librqbit_core::magnet::*;
96pub use librqbit_core::peer_id::*;
97pub use librqbit_core::torrent_metainfo::*;
98
99#[cfg(test)]
100mod tests;
101
102/// The cargo version of librqbit.
103pub const fn version() -> &'static str {
104    env!("CARGO_PKG_VERSION")
105}
106
107pub const fn client_name_and_version() -> &'static str {
108    concat!("rqbit ", env!("CARGO_PKG_VERSION"))
109}
110
111pub fn try_increase_nofile_limit() -> anyhow::Result<u64> {
112    Ok(rlimit::increase_nofile_limit(1024 * 1024)?)
113}