Skip to main content

Server

Struct Server 

Source
pub struct Server { /* private fields */ }
Expand description

A server that is bound and ready to run or spawn, with its options.

Implementations§

Source§

impl Server

Source

pub fn bind<A, F>(addr: A, app: F) -> Result<Server>
where A: ToSocketAddrs, F: Fn() -> App + Send + Sync + 'static,

Listen on addr ("127.0.0.1:0" picks a free port) with a fresh random token, to serve the apps app makes.

In a session’s own process (Isolation::Processes, the default), this is where the session runs: the process this program started for a browser tab reaches this same call, runs the app for that tab, and exits here, without listening.

Examples found in repository?
examples/serve.rs (line 74)
70fn main() -> std::io::Result<()> {
71    let addr = std::env::args()
72        .nth(1)
73        .unwrap_or_else(|| "127.0.0.1:8080".to_string());
74    rich_web::Server::bind(addr.as_str(), app)?
75        .title("rs-rich-web example")
76        .run()
77}
More examples
Hide additional examples
examples/isolated.rs (line 63)
42fn main() -> std::io::Result<()> {
43    let mut args = std::env::args().skip(1);
44    let mut addr = "127.0.0.1:8080".to_string();
45    let mut memory = 256u64 << 20;
46    let mut cpu = 10u64;
47    let mut token = None;
48    let mut startup = None;
49    while let Some(arg) = args.next() {
50        let mut value = || args.next().expect("a value after the option");
51        match arg.as_str() {
52            "--memory" => memory = value().parse().expect("bytes"),
53            "--cpu" => cpu = value().parse().expect("seconds"),
54            "--token" => token = Some(value()),
55            "--startup-memory" => startup = Some(value().parse::<usize>().expect("bytes")),
56            _ => addr = arg,
57        }
58    }
59    // Startup work in each session's process, before it reaches `bind`.
60    if let (Some(bytes), true) = (startup, std::env::var_os(rich_web::SESSION_ENV).is_some()) {
61        std::hint::black_box(vec![1u8; bytes]);
62    }
63    let mut server = rich_web::Server::bind(addr.as_str(), app)?
64        .title("isolated sessions")
65        .session_memory(memory)
66        .session_cpu(Duration::from_secs(cpu));
67    if let Some(token) = token {
68        server = server.token(token);
69    }
70    server.run()
71}
examples/session_probe.rs (line 85)
65fn main() -> std::io::Result<()> {
66    let mut args = std::env::args().skip(1);
67    let mut addr = "127.0.0.1:8080".to_string();
68    let mut token = None;
69    let mut startup = None;
70    let mut stdin_stop = false;
71    let mut nested = false;
72    while let Some(arg) = args.next() {
73        let mut value = || args.next().expect("a value after the option");
74        match arg.as_str() {
75            "--token" => token = Some(value()),
76            "--startup-sleep" => startup = Some(value().parse::<u64>().expect("ms")),
77            "--stdin-stop" => stdin_stop = true,
78            "--nested" => nested = true,
79            _ => addr = arg,
80        }
81    }
82    if nested {
83        // An unrelated program that serves an app: it should get the
84        // address it asked for.
85        let server = rich_web::Server::bind(addr.as_str(), app)?;
86        println!("BOUND {}", server.local_addr());
87        return Ok(());
88    }
89    if let (Some(ms), true) = (startup, std::env::var_os(rich_web::SESSION_ENV).is_some()) {
90        std::thread::sleep(Duration::from_millis(ms));
91    }
92    let mut server = rich_web::Server::bind(addr.as_str(), app)?.title("session probe");
93    if let Some(token) = token {
94        server = server.token(token);
95    }
96    if stdin_stop {
97        let handle = server.spawn()?;
98        println!("Serving session probe at {}", handle.url());
99        let mut line = String::new();
100        std::io::stdin().lock().read_line(&mut line)?;
101        let started = Instant::now();
102        handle.stop();
103        println!("STOPPED {}", started.elapsed().as_millis());
104        return Ok(());
105    }
106    server.run()
107}
Source

pub fn bind_command<A>(addr: A, command: impl Into<Command>) -> Result<Server>
where A: ToSocketAddrs,

Listen on addr with a fresh random token, to run command on a pseudo-terminal of its own for each tab (through LocalPty). The page’s title is the program’s name unless set.

Source

pub fn bind_host<A, F>(addr: A, host: F) -> Result<Server>
where A: ToSocketAddrs, F: Fn() -> Box<dyn PtyHost> + Send + Sync + 'static,

Listen on addr with a fresh random token, to run a program on the PtyHost host makes for each tab: an SSH session, a container’s exec stream, or a test host. It is made, started and dropped on the session’s own thread. max_buffered bounds only what the session holds: a host that reads ahead buffers on its own terms.

Source

pub fn isolation(self, isolation: Isolation) -> Server

Where an app’s sessions run: each in a process of its own (Isolation::Processes, the default), or each on a thread of the server (Isolation::Threads). A program’s sessions (a command, a host) are processes already, and this does not change them.

Source

pub fn session_command<P, I, S>(self, program: P, args: I) -> Server
where P: Into<PathBuf>, I: IntoIterator<Item = S>, S: Into<OsString>,

Start each session’s process as program with args, rather than as this program with the arguments it was given. It must reach the same serve or Server::bind call: an interpreter running the same script, say (Python’s rs_rich.tui.serve passes its own).

Source

pub fn session_memory(self, bytes: u64) -> Server

Cap each session’s process at bytes of memory (its address space): an allocation past it fails, and the process ends, alone. On Linux it holds from the moment the process starts; on other Unix systems from when it reaches serve; macOS has no such limit, and elsewhere (Windows) it is not applied.

Examples found in repository?
examples/isolated.rs (line 65)
42fn main() -> std::io::Result<()> {
43    let mut args = std::env::args().skip(1);
44    let mut addr = "127.0.0.1:8080".to_string();
45    let mut memory = 256u64 << 20;
46    let mut cpu = 10u64;
47    let mut token = None;
48    let mut startup = None;
49    while let Some(arg) = args.next() {
50        let mut value = || args.next().expect("a value after the option");
51        match arg.as_str() {
52            "--memory" => memory = value().parse().expect("bytes"),
53            "--cpu" => cpu = value().parse().expect("seconds"),
54            "--token" => token = Some(value()),
55            "--startup-memory" => startup = Some(value().parse::<usize>().expect("bytes")),
56            _ => addr = arg,
57        }
58    }
59    // Startup work in each session's process, before it reaches `bind`.
60    if let (Some(bytes), true) = (startup, std::env::var_os(rich_web::SESSION_ENV).is_some()) {
61        std::hint::black_box(vec![1u8; bytes]);
62    }
63    let mut server = rich_web::Server::bind(addr.as_str(), app)?
64        .title("isolated sessions")
65        .session_memory(memory)
66        .session_cpu(Duration::from_secs(cpu));
67    if let Some(token) = token {
68        server = server.token(token);
69    }
70    server.run()
71}
Source

pub fn session_cpu(self, time: Duration) -> Server

Cap each session’s process at time of CPU (whole seconds, at least one): past it the process is killed, alone. A session that waits for input uses none. On Linux it holds from the moment the process starts; on other Unix systems from when it reaches serve; elsewhere (Windows) it is not applied.

Examples found in repository?
examples/isolated.rs (line 66)
42fn main() -> std::io::Result<()> {
43    let mut args = std::env::args().skip(1);
44    let mut addr = "127.0.0.1:8080".to_string();
45    let mut memory = 256u64 << 20;
46    let mut cpu = 10u64;
47    let mut token = None;
48    let mut startup = None;
49    while let Some(arg) = args.next() {
50        let mut value = || args.next().expect("a value after the option");
51        match arg.as_str() {
52            "--memory" => memory = value().parse().expect("bytes"),
53            "--cpu" => cpu = value().parse().expect("seconds"),
54            "--token" => token = Some(value()),
55            "--startup-memory" => startup = Some(value().parse::<usize>().expect("bytes")),
56            _ => addr = arg,
57        }
58    }
59    // Startup work in each session's process, before it reaches `bind`.
60    if let (Some(bytes), true) = (startup, std::env::var_os(rich_web::SESSION_ENV).is_some()) {
61        std::hint::black_box(vec![1u8; bytes]);
62    }
63    let mut server = rich_web::Server::bind(addr.as_str(), app)?
64        .title("isolated sessions")
65        .session_memory(memory)
66        .session_cpu(Duration::from_secs(cpu));
67    if let Some(token) = token {
68        server = server.token(token);
69    }
70    server.run()
71}
Source

pub fn max_sessions(self, n: usize) -> Server

Run at most n sessions at once (8 by default); a browser that opens one more is refused until one ends.

Source

pub fn max_buffered(self, bytes: usize) -> Server

For a program: hold at most about bytes of its output for a page that has not shown it yet (1 MiB by default). Half is output sent and not yet acknowledged by the page, half is output read from the program and not yet sent; past that, the program’s writes wait until the page catches up, as on a slow terminal, so nothing is dropped and memory stays bounded however fast it writes, at any size (a LocalPty with backpressure never drops output, even past its own 16 MiB limit without it). Apps send whole frames and are not affected.

Source

pub fn compress(self, from: Option<usize>) -> Server

Compress frames of from bytes or more with deflate, for pages that can undo it (they have DecompressionStream, and ask with z=1): an app’s frames, the DOM renderer’s messages and a program’s output. Off (None) by default. Worth it over a slow link: measured on a few scenes, frames shrink to 5 to 30% of their size for 15 to 60 µs each (level 1). On a local machine it only adds work. 1024 is a fair threshold.

Source

pub fn renderer(self, renderer: Renderer) -> Server

How an app’s page draws it: Renderer::Xterm (the default) or Renderer::Dom. A page’s address can ask for either with &renderer=xterm or &renderer=dom. A program is always drawn by xterm.js.

Source

pub fn token(self, token: impl Into<String>) -> Server

Use token instead of a random one, for an address that stays the same between runs. Keep it as secret, and as long: anyone with it can use the app.

§Panics

When token is empty or has characters other than ASCII letters, digits, -, _, . and ~ (it goes in a URL as it is).

Examples found in repository?
examples/isolated.rs (line 68)
42fn main() -> std::io::Result<()> {
43    let mut args = std::env::args().skip(1);
44    let mut addr = "127.0.0.1:8080".to_string();
45    let mut memory = 256u64 << 20;
46    let mut cpu = 10u64;
47    let mut token = None;
48    let mut startup = None;
49    while let Some(arg) = args.next() {
50        let mut value = || args.next().expect("a value after the option");
51        match arg.as_str() {
52            "--memory" => memory = value().parse().expect("bytes"),
53            "--cpu" => cpu = value().parse().expect("seconds"),
54            "--token" => token = Some(value()),
55            "--startup-memory" => startup = Some(value().parse::<usize>().expect("bytes")),
56            _ => addr = arg,
57        }
58    }
59    // Startup work in each session's process, before it reaches `bind`.
60    if let (Some(bytes), true) = (startup, std::env::var_os(rich_web::SESSION_ENV).is_some()) {
61        std::hint::black_box(vec![1u8; bytes]);
62    }
63    let mut server = rich_web::Server::bind(addr.as_str(), app)?
64        .title("isolated sessions")
65        .session_memory(memory)
66        .session_cpu(Duration::from_secs(cpu));
67    if let Some(token) = token {
68        server = server.token(token);
69    }
70    server.run()
71}
More examples
Hide additional examples
examples/session_probe.rs (line 94)
65fn main() -> std::io::Result<()> {
66    let mut args = std::env::args().skip(1);
67    let mut addr = "127.0.0.1:8080".to_string();
68    let mut token = None;
69    let mut startup = None;
70    let mut stdin_stop = false;
71    let mut nested = false;
72    while let Some(arg) = args.next() {
73        let mut value = || args.next().expect("a value after the option");
74        match arg.as_str() {
75            "--token" => token = Some(value()),
76            "--startup-sleep" => startup = Some(value().parse::<u64>().expect("ms")),
77            "--stdin-stop" => stdin_stop = true,
78            "--nested" => nested = true,
79            _ => addr = arg,
80        }
81    }
82    if nested {
83        // An unrelated program that serves an app: it should get the
84        // address it asked for.
85        let server = rich_web::Server::bind(addr.as_str(), app)?;
86        println!("BOUND {}", server.local_addr());
87        return Ok(());
88    }
89    if let (Some(ms), true) = (startup, std::env::var_os(rich_web::SESSION_ENV).is_some()) {
90        std::thread::sleep(Duration::from_millis(ms));
91    }
92    let mut server = rich_web::Server::bind(addr.as_str(), app)?.title("session probe");
93    if let Some(token) = token {
94        server = server.token(token);
95    }
96    if stdin_stop {
97        let handle = server.spawn()?;
98        println!("Serving session probe at {}", handle.url());
99        let mut line = String::new();
100        std::io::stdin().lock().read_line(&mut line)?;
101        let started = Instant::now();
102        handle.stop();
103        println!("STOPPED {}", started.elapsed().as_millis());
104        return Ok(());
105    }
106    server.run()
107}
Source

pub fn allow_host(self, host: impl AsRef<str>) -> Server

Also answer to host (say "box.lan", or "box.lan:9000"): a name this machine is reached by that the server does not know itself. The server’s port is added unless host names one. The Host of a WebSocket upgrade must be one the server answers to: its bound address (with localhost for a loopback one), or, bound to all interfaces, the loopback addresses, localhost, this machine’s own name and the address the connection arrived on; plus these. That is what stops a page whose name was pointed here (DNS rebinding). The token is still required.

Source

pub fn allow_origin(self, origin: impl Into<String>) -> Server

Also accept WebSocket upgrades from pages served at origin (say "https://term.example.com"): the address a reverse proxy serves this server’s page from. The token is still required.

Source

pub fn title(self, title: impl Into<String>) -> Server

The page’s title (intuiTUIve for an app, the program’s name for a command, by default).

Examples found in repository?
examples/serve.rs (line 75)
70fn main() -> std::io::Result<()> {
71    let addr = std::env::args()
72        .nth(1)
73        .unwrap_or_else(|| "127.0.0.1:8080".to_string());
74    rich_web::Server::bind(addr.as_str(), app)?
75        .title("rs-rich-web example")
76        .run()
77}
More examples
Hide additional examples
examples/isolated.rs (line 64)
42fn main() -> std::io::Result<()> {
43    let mut args = std::env::args().skip(1);
44    let mut addr = "127.0.0.1:8080".to_string();
45    let mut memory = 256u64 << 20;
46    let mut cpu = 10u64;
47    let mut token = None;
48    let mut startup = None;
49    while let Some(arg) = args.next() {
50        let mut value = || args.next().expect("a value after the option");
51        match arg.as_str() {
52            "--memory" => memory = value().parse().expect("bytes"),
53            "--cpu" => cpu = value().parse().expect("seconds"),
54            "--token" => token = Some(value()),
55            "--startup-memory" => startup = Some(value().parse::<usize>().expect("bytes")),
56            _ => addr = arg,
57        }
58    }
59    // Startup work in each session's process, before it reaches `bind`.
60    if let (Some(bytes), true) = (startup, std::env::var_os(rich_web::SESSION_ENV).is_some()) {
61        std::hint::black_box(vec![1u8; bytes]);
62    }
63    let mut server = rich_web::Server::bind(addr.as_str(), app)?
64        .title("isolated sessions")
65        .session_memory(memory)
66        .session_cpu(Duration::from_secs(cpu));
67    if let Some(token) = token {
68        server = server.token(token);
69    }
70    server.run()
71}
examples/session_probe.rs (line 92)
65fn main() -> std::io::Result<()> {
66    let mut args = std::env::args().skip(1);
67    let mut addr = "127.0.0.1:8080".to_string();
68    let mut token = None;
69    let mut startup = None;
70    let mut stdin_stop = false;
71    let mut nested = false;
72    while let Some(arg) = args.next() {
73        let mut value = || args.next().expect("a value after the option");
74        match arg.as_str() {
75            "--token" => token = Some(value()),
76            "--startup-sleep" => startup = Some(value().parse::<u64>().expect("ms")),
77            "--stdin-stop" => stdin_stop = true,
78            "--nested" => nested = true,
79            _ => addr = arg,
80        }
81    }
82    if nested {
83        // An unrelated program that serves an app: it should get the
84        // address it asked for.
85        let server = rich_web::Server::bind(addr.as_str(), app)?;
86        println!("BOUND {}", server.local_addr());
87        return Ok(());
88    }
89    if let (Some(ms), true) = (startup, std::env::var_os(rich_web::SESSION_ENV).is_some()) {
90        std::thread::sleep(Duration::from_millis(ms));
91    }
92    let mut server = rich_web::Server::bind(addr.as_str(), app)?.title("session probe");
93    if let Some(token) = token {
94        server = server.token(token);
95    }
96    if stdin_stop {
97        let handle = server.spawn()?;
98        println!("Serving session probe at {}", handle.url());
99        let mut line = String::new();
100        std::io::stdin().lock().read_line(&mut line)?;
101        let started = Instant::now();
102        handle.stop();
103        println!("STOPPED {}", started.elapsed().as_millis());
104        return Ok(());
105    }
106    server.run()
107}
Source

pub fn local_addr(&self) -> SocketAddr

The address the server listens on.

Examples found in repository?
examples/session_probe.rs (line 86)
65fn main() -> std::io::Result<()> {
66    let mut args = std::env::args().skip(1);
67    let mut addr = "127.0.0.1:8080".to_string();
68    let mut token = None;
69    let mut startup = None;
70    let mut stdin_stop = false;
71    let mut nested = false;
72    while let Some(arg) = args.next() {
73        let mut value = || args.next().expect("a value after the option");
74        match arg.as_str() {
75            "--token" => token = Some(value()),
76            "--startup-sleep" => startup = Some(value().parse::<u64>().expect("ms")),
77            "--stdin-stop" => stdin_stop = true,
78            "--nested" => nested = true,
79            _ => addr = arg,
80        }
81    }
82    if nested {
83        // An unrelated program that serves an app: it should get the
84        // address it asked for.
85        let server = rich_web::Server::bind(addr.as_str(), app)?;
86        println!("BOUND {}", server.local_addr());
87        return Ok(());
88    }
89    if let (Some(ms), true) = (startup, std::env::var_os(rich_web::SESSION_ENV).is_some()) {
90        std::thread::sleep(Duration::from_millis(ms));
91    }
92    let mut server = rich_web::Server::bind(addr.as_str(), app)?.title("session probe");
93    if let Some(token) = token {
94        server = server.token(token);
95    }
96    if stdin_stop {
97        let handle = server.spawn()?;
98        println!("Serving session probe at {}", handle.url());
99        let mut line = String::new();
100        std::io::stdin().lock().read_line(&mut line)?;
101        let started = Instant::now();
102        handle.stop();
103        println!("STOPPED {}", started.elapsed().as_millis());
104        return Ok(());
105    }
106    server.run()
107}
Source

pub fn access_token(&self) -> &str

The token browsers must give.

Source

pub fn url(&self) -> String

The address to open in a browser, with the token.

Source

pub fn run(self) -> Result<()>

Print the URL (and a warning when the address is not loopback), then serve until the process ends.

Examples found in repository?
examples/serve.rs (line 76)
70fn main() -> std::io::Result<()> {
71    let addr = std::env::args()
72        .nth(1)
73        .unwrap_or_else(|| "127.0.0.1:8080".to_string());
74    rich_web::Server::bind(addr.as_str(), app)?
75        .title("rs-rich-web example")
76        .run()
77}
More examples
Hide additional examples
examples/isolated.rs (line 70)
42fn main() -> std::io::Result<()> {
43    let mut args = std::env::args().skip(1);
44    let mut addr = "127.0.0.1:8080".to_string();
45    let mut memory = 256u64 << 20;
46    let mut cpu = 10u64;
47    let mut token = None;
48    let mut startup = None;
49    while let Some(arg) = args.next() {
50        let mut value = || args.next().expect("a value after the option");
51        match arg.as_str() {
52            "--memory" => memory = value().parse().expect("bytes"),
53            "--cpu" => cpu = value().parse().expect("seconds"),
54            "--token" => token = Some(value()),
55            "--startup-memory" => startup = Some(value().parse::<usize>().expect("bytes")),
56            _ => addr = arg,
57        }
58    }
59    // Startup work in each session's process, before it reaches `bind`.
60    if let (Some(bytes), true) = (startup, std::env::var_os(rich_web::SESSION_ENV).is_some()) {
61        std::hint::black_box(vec![1u8; bytes]);
62    }
63    let mut server = rich_web::Server::bind(addr.as_str(), app)?
64        .title("isolated sessions")
65        .session_memory(memory)
66        .session_cpu(Duration::from_secs(cpu));
67    if let Some(token) = token {
68        server = server.token(token);
69    }
70    server.run()
71}
examples/session_probe.rs (line 106)
65fn main() -> std::io::Result<()> {
66    let mut args = std::env::args().skip(1);
67    let mut addr = "127.0.0.1:8080".to_string();
68    let mut token = None;
69    let mut startup = None;
70    let mut stdin_stop = false;
71    let mut nested = false;
72    while let Some(arg) = args.next() {
73        let mut value = || args.next().expect("a value after the option");
74        match arg.as_str() {
75            "--token" => token = Some(value()),
76            "--startup-sleep" => startup = Some(value().parse::<u64>().expect("ms")),
77            "--stdin-stop" => stdin_stop = true,
78            "--nested" => nested = true,
79            _ => addr = arg,
80        }
81    }
82    if nested {
83        // An unrelated program that serves an app: it should get the
84        // address it asked for.
85        let server = rich_web::Server::bind(addr.as_str(), app)?;
86        println!("BOUND {}", server.local_addr());
87        return Ok(());
88    }
89    if let (Some(ms), true) = (startup, std::env::var_os(rich_web::SESSION_ENV).is_some()) {
90        std::thread::sleep(Duration::from_millis(ms));
91    }
92    let mut server = rich_web::Server::bind(addr.as_str(), app)?.title("session probe");
93    if let Some(token) = token {
94        server = server.token(token);
95    }
96    if stdin_stop {
97        let handle = server.spawn()?;
98        println!("Serving session probe at {}", handle.url());
99        let mut line = String::new();
100        std::io::stdin().lock().read_line(&mut line)?;
101        let started = Instant::now();
102        handle.stop();
103        println!("STOPPED {}", started.elapsed().as_millis());
104        return Ok(());
105    }
106    server.run()
107}
Source

pub fn run_until(self, until: impl FnOnce()) -> Result<()>

Print the URL as run does, then serve until until returns, and stop as Handle::stop does: every session ends, and this returns once their programs have. until runs on this thread: a wait for a signal, say, as rich serve waits for Ctrl+C, so that no program outlives the server.

Source

pub fn spawn(self) -> Result<Handle>

Serve on a thread of its own, printing nothing, until the Handle is stopped or dropped.

Examples found in repository?
examples/session_probe.rs (line 97)
65fn main() -> std::io::Result<()> {
66    let mut args = std::env::args().skip(1);
67    let mut addr = "127.0.0.1:8080".to_string();
68    let mut token = None;
69    let mut startup = None;
70    let mut stdin_stop = false;
71    let mut nested = false;
72    while let Some(arg) = args.next() {
73        let mut value = || args.next().expect("a value after the option");
74        match arg.as_str() {
75            "--token" => token = Some(value()),
76            "--startup-sleep" => startup = Some(value().parse::<u64>().expect("ms")),
77            "--stdin-stop" => stdin_stop = true,
78            "--nested" => nested = true,
79            _ => addr = arg,
80        }
81    }
82    if nested {
83        // An unrelated program that serves an app: it should get the
84        // address it asked for.
85        let server = rich_web::Server::bind(addr.as_str(), app)?;
86        println!("BOUND {}", server.local_addr());
87        return Ok(());
88    }
89    if let (Some(ms), true) = (startup, std::env::var_os(rich_web::SESSION_ENV).is_some()) {
90        std::thread::sleep(Duration::from_millis(ms));
91    }
92    let mut server = rich_web::Server::bind(addr.as_str(), app)?.title("session probe");
93    if let Some(token) = token {
94        server = server.token(token);
95    }
96    if stdin_stop {
97        let handle = server.spawn()?;
98        println!("Serving session probe at {}", handle.url());
99        let mut line = String::new();
100        std::io::stdin().lock().read_line(&mut line)?;
101        let started = Instant::now();
102        handle.stop();
103        println!("STOPPED {}", started.elapsed().as_millis());
104        return Ok(());
105    }
106    server.run()
107}

Auto Trait Implementations§

§

impl !Freeze for Server

§

impl !RefUnwindSafe for Server

§

impl !UnwindSafe for Server

§

impl Send for Server

§

impl Sync for Server

§

impl Unpin for Server

§

impl UnsafeUnpin for Server

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.