SandboxBuilder

Struct SandboxBuilder 

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

Builder pattern for sandbox creation

Implementations§

Source§

impl SandboxBuilder

Source

pub fn new(id: &str) -> Self

Create new builder

Examples found in repository?
examples/basic.rs (line 11)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    println!("=== Sandbox RS - Basic Example ===\n");
8
9    // Create a sandbox with basic configuration
10    println!("[1] Creating sandbox with memory limit...");
11    let mut sandbox = SandboxBuilder::new("example-1")
12        .memory_limit(50 * 1024 * 1024) // 50MB
13        .cpu_limit_percent(50) // 50% of one CPU
14        .timeout(Duration::from_secs(5))
15        .seccomp_profile(SeccompProfile::Minimal)
16        .build()?;
17
18    println!("[*] Sandbox created: {}", sandbox.id());
19    println!("[*] Root: {}", sandbox.root().display());
20    println!(
21        "[*] Status: {}\n",
22        if sandbox.is_running() {
23            "running"
24        } else {
25            "idle"
26        }
27    );
28
29    // Try to run a simple command
30    println!("[2] Running 'echo hello' in sandbox...");
31    let result = sandbox.run("/bin/echo", &["hello", "world"])?;
32
33    println!("[*] Execution result:");
34    println!("Exit code: {}", result.exit_code);
35    println!("Wall time: {} ms", result.wall_time_ms);
36    println!("Memory peak: {} bytes", result.memory_peak);
37    println!("CPU time: {} μs", result.cpu_time_us);
38    println!("Timed out: {}\n", result.timed_out);
39
40    Ok(())
41}
More examples
Hide additional examples
examples/cgroup_limits.rs (line 11)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    println!("=== Sandbox RS - Cgroup Resource Limits ===\n");
8
9    // Example 1: Memory limited sandbox
10    println!("[1] Example: Memory-limited sandbox (100MB)");
11    let sandbox1 = SandboxBuilder::new("mem-limited")
12        .memory_limit_str("100M")?
13        .cpu_limit_percent(100)
14        .build()?;
15    println!("[*] Created: {}", sandbox1.id());
16    println!("[*] Root: {}\n", sandbox1.root().display());
17
18    // Example 2: CPU limited sandbox
19    println!("[2] Example: CPU-limited sandbox (25% of one core)");
20    let sandbox2 = SandboxBuilder::new("cpu-limited")
21        .cpu_limit_percent(25)
22        .memory_limit(512 * 1024 * 1024) // 512MB
23        .timeout(Duration::from_secs(10))
24        .build()?;
25    println!("[*] Created: {}", sandbox2.id());
26    println!("[*] Root: {}\n", sandbox2.root().display());
27
28    // Example 3: Tight limits for untrusted code
29    println!("[3] Example: Tight limits for untrusted code");
30    let sandbox3 = SandboxBuilder::new("untrusted")
31        .memory_limit_str("64M")?
32        .cpu_limit_percent(10)
33        .max_pids(8)
34        .timeout(Duration::from_secs(5))
35        .seccomp_profile(sandbox_rs::SeccompProfile::Minimal)
36        .build()?;
37    println!("[*] Created: {}", sandbox3.id());
38    println!("[*] Root: {}\n", sandbox3.root().display());
39
40    println!("[*] All sandboxes created successfully!");
41    println!("[*] Note: Actual resource enforcement requires root permissions");
42
43    Ok(())
44}
Source

pub fn memory_limit(self, bytes: u64) -> Self

Set memory limit

Examples found in repository?
examples/basic.rs (line 12)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    println!("=== Sandbox RS - Basic Example ===\n");
8
9    // Create a sandbox with basic configuration
10    println!("[1] Creating sandbox with memory limit...");
11    let mut sandbox = SandboxBuilder::new("example-1")
12        .memory_limit(50 * 1024 * 1024) // 50MB
13        .cpu_limit_percent(50) // 50% of one CPU
14        .timeout(Duration::from_secs(5))
15        .seccomp_profile(SeccompProfile::Minimal)
16        .build()?;
17
18    println!("[*] Sandbox created: {}", sandbox.id());
19    println!("[*] Root: {}", sandbox.root().display());
20    println!(
21        "[*] Status: {}\n",
22        if sandbox.is_running() {
23            "running"
24        } else {
25            "idle"
26        }
27    );
28
29    // Try to run a simple command
30    println!("[2] Running 'echo hello' in sandbox...");
31    let result = sandbox.run("/bin/echo", &["hello", "world"])?;
32
33    println!("[*] Execution result:");
34    println!("Exit code: {}", result.exit_code);
35    println!("Wall time: {} ms", result.wall_time_ms);
36    println!("Memory peak: {} bytes", result.memory_peak);
37    println!("CPU time: {} μs", result.cpu_time_us);
38    println!("Timed out: {}\n", result.timed_out);
39
40    Ok(())
41}
More examples
Hide additional examples
examples/cgroup_limits.rs (line 22)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    println!("=== Sandbox RS - Cgroup Resource Limits ===\n");
8
9    // Example 1: Memory limited sandbox
10    println!("[1] Example: Memory-limited sandbox (100MB)");
11    let sandbox1 = SandboxBuilder::new("mem-limited")
12        .memory_limit_str("100M")?
13        .cpu_limit_percent(100)
14        .build()?;
15    println!("[*] Created: {}", sandbox1.id());
16    println!("[*] Root: {}\n", sandbox1.root().display());
17
18    // Example 2: CPU limited sandbox
19    println!("[2] Example: CPU-limited sandbox (25% of one core)");
20    let sandbox2 = SandboxBuilder::new("cpu-limited")
21        .cpu_limit_percent(25)
22        .memory_limit(512 * 1024 * 1024) // 512MB
23        .timeout(Duration::from_secs(10))
24        .build()?;
25    println!("[*] Created: {}", sandbox2.id());
26    println!("[*] Root: {}\n", sandbox2.root().display());
27
28    // Example 3: Tight limits for untrusted code
29    println!("[3] Example: Tight limits for untrusted code");
30    let sandbox3 = SandboxBuilder::new("untrusted")
31        .memory_limit_str("64M")?
32        .cpu_limit_percent(10)
33        .max_pids(8)
34        .timeout(Duration::from_secs(5))
35        .seccomp_profile(sandbox_rs::SeccompProfile::Minimal)
36        .build()?;
37    println!("[*] Created: {}", sandbox3.id());
38    println!("[*] Root: {}\n", sandbox3.root().display());
39
40    println!("[*] All sandboxes created successfully!");
41    println!("[*] Note: Actual resource enforcement requires root permissions");
42
43    Ok(())
44}
Source

pub fn memory_limit_str(self, s: &str) -> Result<Self>

Set memory limit from string (e.g., “100M”)

Examples found in repository?
examples/cgroup_limits.rs (line 12)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    println!("=== Sandbox RS - Cgroup Resource Limits ===\n");
8
9    // Example 1: Memory limited sandbox
10    println!("[1] Example: Memory-limited sandbox (100MB)");
11    let sandbox1 = SandboxBuilder::new("mem-limited")
12        .memory_limit_str("100M")?
13        .cpu_limit_percent(100)
14        .build()?;
15    println!("[*] Created: {}", sandbox1.id());
16    println!("[*] Root: {}\n", sandbox1.root().display());
17
18    // Example 2: CPU limited sandbox
19    println!("[2] Example: CPU-limited sandbox (25% of one core)");
20    let sandbox2 = SandboxBuilder::new("cpu-limited")
21        .cpu_limit_percent(25)
22        .memory_limit(512 * 1024 * 1024) // 512MB
23        .timeout(Duration::from_secs(10))
24        .build()?;
25    println!("[*] Created: {}", sandbox2.id());
26    println!("[*] Root: {}\n", sandbox2.root().display());
27
28    // Example 3: Tight limits for untrusted code
29    println!("[3] Example: Tight limits for untrusted code");
30    let sandbox3 = SandboxBuilder::new("untrusted")
31        .memory_limit_str("64M")?
32        .cpu_limit_percent(10)
33        .max_pids(8)
34        .timeout(Duration::from_secs(5))
35        .seccomp_profile(sandbox_rs::SeccompProfile::Minimal)
36        .build()?;
37    println!("[*] Created: {}", sandbox3.id());
38    println!("[*] Root: {}\n", sandbox3.root().display());
39
40    println!("[*] All sandboxes created successfully!");
41    println!("[*] Note: Actual resource enforcement requires root permissions");
42
43    Ok(())
44}
Source

pub fn cpu_quota(self, quota: u64, period: u64) -> Self

Set CPU quota

Source

pub fn cpu_limit_percent(self, percent: u32) -> Self

Set CPU limit by percentage (0-100)

Examples found in repository?
examples/basic.rs (line 13)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    println!("=== Sandbox RS - Basic Example ===\n");
8
9    // Create a sandbox with basic configuration
10    println!("[1] Creating sandbox with memory limit...");
11    let mut sandbox = SandboxBuilder::new("example-1")
12        .memory_limit(50 * 1024 * 1024) // 50MB
13        .cpu_limit_percent(50) // 50% of one CPU
14        .timeout(Duration::from_secs(5))
15        .seccomp_profile(SeccompProfile::Minimal)
16        .build()?;
17
18    println!("[*] Sandbox created: {}", sandbox.id());
19    println!("[*] Root: {}", sandbox.root().display());
20    println!(
21        "[*] Status: {}\n",
22        if sandbox.is_running() {
23            "running"
24        } else {
25            "idle"
26        }
27    );
28
29    // Try to run a simple command
30    println!("[2] Running 'echo hello' in sandbox...");
31    let result = sandbox.run("/bin/echo", &["hello", "world"])?;
32
33    println!("[*] Execution result:");
34    println!("Exit code: {}", result.exit_code);
35    println!("Wall time: {} ms", result.wall_time_ms);
36    println!("Memory peak: {} bytes", result.memory_peak);
37    println!("CPU time: {} μs", result.cpu_time_us);
38    println!("Timed out: {}\n", result.timed_out);
39
40    Ok(())
41}
More examples
Hide additional examples
examples/cgroup_limits.rs (line 13)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    println!("=== Sandbox RS - Cgroup Resource Limits ===\n");
8
9    // Example 1: Memory limited sandbox
10    println!("[1] Example: Memory-limited sandbox (100MB)");
11    let sandbox1 = SandboxBuilder::new("mem-limited")
12        .memory_limit_str("100M")?
13        .cpu_limit_percent(100)
14        .build()?;
15    println!("[*] Created: {}", sandbox1.id());
16    println!("[*] Root: {}\n", sandbox1.root().display());
17
18    // Example 2: CPU limited sandbox
19    println!("[2] Example: CPU-limited sandbox (25% of one core)");
20    let sandbox2 = SandboxBuilder::new("cpu-limited")
21        .cpu_limit_percent(25)
22        .memory_limit(512 * 1024 * 1024) // 512MB
23        .timeout(Duration::from_secs(10))
24        .build()?;
25    println!("[*] Created: {}", sandbox2.id());
26    println!("[*] Root: {}\n", sandbox2.root().display());
27
28    // Example 3: Tight limits for untrusted code
29    println!("[3] Example: Tight limits for untrusted code");
30    let sandbox3 = SandboxBuilder::new("untrusted")
31        .memory_limit_str("64M")?
32        .cpu_limit_percent(10)
33        .max_pids(8)
34        .timeout(Duration::from_secs(5))
35        .seccomp_profile(sandbox_rs::SeccompProfile::Minimal)
36        .build()?;
37    println!("[*] Created: {}", sandbox3.id());
38    println!("[*] Root: {}\n", sandbox3.root().display());
39
40    println!("[*] All sandboxes created successfully!");
41    println!("[*] Note: Actual resource enforcement requires root permissions");
42
43    Ok(())
44}
Source

pub fn max_pids(self, max: u32) -> Self

Set maximum PIDs

Examples found in repository?
examples/cgroup_limits.rs (line 33)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    println!("=== Sandbox RS - Cgroup Resource Limits ===\n");
8
9    // Example 1: Memory limited sandbox
10    println!("[1] Example: Memory-limited sandbox (100MB)");
11    let sandbox1 = SandboxBuilder::new("mem-limited")
12        .memory_limit_str("100M")?
13        .cpu_limit_percent(100)
14        .build()?;
15    println!("[*] Created: {}", sandbox1.id());
16    println!("[*] Root: {}\n", sandbox1.root().display());
17
18    // Example 2: CPU limited sandbox
19    println!("[2] Example: CPU-limited sandbox (25% of one core)");
20    let sandbox2 = SandboxBuilder::new("cpu-limited")
21        .cpu_limit_percent(25)
22        .memory_limit(512 * 1024 * 1024) // 512MB
23        .timeout(Duration::from_secs(10))
24        .build()?;
25    println!("[*] Created: {}", sandbox2.id());
26    println!("[*] Root: {}\n", sandbox2.root().display());
27
28    // Example 3: Tight limits for untrusted code
29    println!("[3] Example: Tight limits for untrusted code");
30    let sandbox3 = SandboxBuilder::new("untrusted")
31        .memory_limit_str("64M")?
32        .cpu_limit_percent(10)
33        .max_pids(8)
34        .timeout(Duration::from_secs(5))
35        .seccomp_profile(sandbox_rs::SeccompProfile::Minimal)
36        .build()?;
37    println!("[*] Created: {}", sandbox3.id());
38    println!("[*] Root: {}\n", sandbox3.root().display());
39
40    println!("[*] All sandboxes created successfully!");
41    println!("[*] Note: Actual resource enforcement requires root permissions");
42
43    Ok(())
44}
Source

pub fn seccomp_profile(self, profile: SeccompProfile) -> Self

Set seccomp profile

Examples found in repository?
examples/basic.rs (line 15)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    println!("=== Sandbox RS - Basic Example ===\n");
8
9    // Create a sandbox with basic configuration
10    println!("[1] Creating sandbox with memory limit...");
11    let mut sandbox = SandboxBuilder::new("example-1")
12        .memory_limit(50 * 1024 * 1024) // 50MB
13        .cpu_limit_percent(50) // 50% of one CPU
14        .timeout(Duration::from_secs(5))
15        .seccomp_profile(SeccompProfile::Minimal)
16        .build()?;
17
18    println!("[*] Sandbox created: {}", sandbox.id());
19    println!("[*] Root: {}", sandbox.root().display());
20    println!(
21        "[*] Status: {}\n",
22        if sandbox.is_running() {
23            "running"
24        } else {
25            "idle"
26        }
27    );
28
29    // Try to run a simple command
30    println!("[2] Running 'echo hello' in sandbox...");
31    let result = sandbox.run("/bin/echo", &["hello", "world"])?;
32
33    println!("[*] Execution result:");
34    println!("Exit code: {}", result.exit_code);
35    println!("Wall time: {} ms", result.wall_time_ms);
36    println!("Memory peak: {} bytes", result.memory_peak);
37    println!("CPU time: {} μs", result.cpu_time_us);
38    println!("Timed out: {}\n", result.timed_out);
39
40    Ok(())
41}
More examples
Hide additional examples
examples/cgroup_limits.rs (line 35)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    println!("=== Sandbox RS - Cgroup Resource Limits ===\n");
8
9    // Example 1: Memory limited sandbox
10    println!("[1] Example: Memory-limited sandbox (100MB)");
11    let sandbox1 = SandboxBuilder::new("mem-limited")
12        .memory_limit_str("100M")?
13        .cpu_limit_percent(100)
14        .build()?;
15    println!("[*] Created: {}", sandbox1.id());
16    println!("[*] Root: {}\n", sandbox1.root().display());
17
18    // Example 2: CPU limited sandbox
19    println!("[2] Example: CPU-limited sandbox (25% of one core)");
20    let sandbox2 = SandboxBuilder::new("cpu-limited")
21        .cpu_limit_percent(25)
22        .memory_limit(512 * 1024 * 1024) // 512MB
23        .timeout(Duration::from_secs(10))
24        .build()?;
25    println!("[*] Created: {}", sandbox2.id());
26    println!("[*] Root: {}\n", sandbox2.root().display());
27
28    // Example 3: Tight limits for untrusted code
29    println!("[3] Example: Tight limits for untrusted code");
30    let sandbox3 = SandboxBuilder::new("untrusted")
31        .memory_limit_str("64M")?
32        .cpu_limit_percent(10)
33        .max_pids(8)
34        .timeout(Duration::from_secs(5))
35        .seccomp_profile(sandbox_rs::SeccompProfile::Minimal)
36        .build()?;
37    println!("[*] Created: {}", sandbox3.id());
38    println!("[*] Root: {}\n", sandbox3.root().display());
39
40    println!("[*] All sandboxes created successfully!");
41    println!("[*] Note: Actual resource enforcement requires root permissions");
42
43    Ok(())
44}
Source

pub fn root(self, path: impl AsRef<Path>) -> Self

Set root directory

Source

pub fn timeout(self, duration: Duration) -> Self

Set timeout

Examples found in repository?
examples/basic.rs (line 14)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    println!("=== Sandbox RS - Basic Example ===\n");
8
9    // Create a sandbox with basic configuration
10    println!("[1] Creating sandbox with memory limit...");
11    let mut sandbox = SandboxBuilder::new("example-1")
12        .memory_limit(50 * 1024 * 1024) // 50MB
13        .cpu_limit_percent(50) // 50% of one CPU
14        .timeout(Duration::from_secs(5))
15        .seccomp_profile(SeccompProfile::Minimal)
16        .build()?;
17
18    println!("[*] Sandbox created: {}", sandbox.id());
19    println!("[*] Root: {}", sandbox.root().display());
20    println!(
21        "[*] Status: {}\n",
22        if sandbox.is_running() {
23            "running"
24        } else {
25            "idle"
26        }
27    );
28
29    // Try to run a simple command
30    println!("[2] Running 'echo hello' in sandbox...");
31    let result = sandbox.run("/bin/echo", &["hello", "world"])?;
32
33    println!("[*] Execution result:");
34    println!("Exit code: {}", result.exit_code);
35    println!("Wall time: {} ms", result.wall_time_ms);
36    println!("Memory peak: {} bytes", result.memory_peak);
37    println!("CPU time: {} μs", result.cpu_time_us);
38    println!("Timed out: {}\n", result.timed_out);
39
40    Ok(())
41}
More examples
Hide additional examples
examples/cgroup_limits.rs (line 23)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    println!("=== Sandbox RS - Cgroup Resource Limits ===\n");
8
9    // Example 1: Memory limited sandbox
10    println!("[1] Example: Memory-limited sandbox (100MB)");
11    let sandbox1 = SandboxBuilder::new("mem-limited")
12        .memory_limit_str("100M")?
13        .cpu_limit_percent(100)
14        .build()?;
15    println!("[*] Created: {}", sandbox1.id());
16    println!("[*] Root: {}\n", sandbox1.root().display());
17
18    // Example 2: CPU limited sandbox
19    println!("[2] Example: CPU-limited sandbox (25% of one core)");
20    let sandbox2 = SandboxBuilder::new("cpu-limited")
21        .cpu_limit_percent(25)
22        .memory_limit(512 * 1024 * 1024) // 512MB
23        .timeout(Duration::from_secs(10))
24        .build()?;
25    println!("[*] Created: {}", sandbox2.id());
26    println!("[*] Root: {}\n", sandbox2.root().display());
27
28    // Example 3: Tight limits for untrusted code
29    println!("[3] Example: Tight limits for untrusted code");
30    let sandbox3 = SandboxBuilder::new("untrusted")
31        .memory_limit_str("64M")?
32        .cpu_limit_percent(10)
33        .max_pids(8)
34        .timeout(Duration::from_secs(5))
35        .seccomp_profile(sandbox_rs::SeccompProfile::Minimal)
36        .build()?;
37    println!("[*] Created: {}", sandbox3.id());
38    println!("[*] Root: {}\n", sandbox3.root().display());
39
40    println!("[*] All sandboxes created successfully!");
41    println!("[*] Note: Actual resource enforcement requires root permissions");
42
43    Ok(())
44}
Source

pub fn namespaces(self, config: NamespaceConfig) -> Self

Set namespace configuration

Source

pub fn build(self) -> Result<Sandbox>

Build sandbox

Examples found in repository?
examples/basic.rs (line 16)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    println!("=== Sandbox RS - Basic Example ===\n");
8
9    // Create a sandbox with basic configuration
10    println!("[1] Creating sandbox with memory limit...");
11    let mut sandbox = SandboxBuilder::new("example-1")
12        .memory_limit(50 * 1024 * 1024) // 50MB
13        .cpu_limit_percent(50) // 50% of one CPU
14        .timeout(Duration::from_secs(5))
15        .seccomp_profile(SeccompProfile::Minimal)
16        .build()?;
17
18    println!("[*] Sandbox created: {}", sandbox.id());
19    println!("[*] Root: {}", sandbox.root().display());
20    println!(
21        "[*] Status: {}\n",
22        if sandbox.is_running() {
23            "running"
24        } else {
25            "idle"
26        }
27    );
28
29    // Try to run a simple command
30    println!("[2] Running 'echo hello' in sandbox...");
31    let result = sandbox.run("/bin/echo", &["hello", "world"])?;
32
33    println!("[*] Execution result:");
34    println!("Exit code: {}", result.exit_code);
35    println!("Wall time: {} ms", result.wall_time_ms);
36    println!("Memory peak: {} bytes", result.memory_peak);
37    println!("CPU time: {} μs", result.cpu_time_us);
38    println!("Timed out: {}\n", result.timed_out);
39
40    Ok(())
41}
More examples
Hide additional examples
examples/cgroup_limits.rs (line 14)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    println!("=== Sandbox RS - Cgroup Resource Limits ===\n");
8
9    // Example 1: Memory limited sandbox
10    println!("[1] Example: Memory-limited sandbox (100MB)");
11    let sandbox1 = SandboxBuilder::new("mem-limited")
12        .memory_limit_str("100M")?
13        .cpu_limit_percent(100)
14        .build()?;
15    println!("[*] Created: {}", sandbox1.id());
16    println!("[*] Root: {}\n", sandbox1.root().display());
17
18    // Example 2: CPU limited sandbox
19    println!("[2] Example: CPU-limited sandbox (25% of one core)");
20    let sandbox2 = SandboxBuilder::new("cpu-limited")
21        .cpu_limit_percent(25)
22        .memory_limit(512 * 1024 * 1024) // 512MB
23        .timeout(Duration::from_secs(10))
24        .build()?;
25    println!("[*] Created: {}", sandbox2.id());
26    println!("[*] Root: {}\n", sandbox2.root().display());
27
28    // Example 3: Tight limits for untrusted code
29    println!("[3] Example: Tight limits for untrusted code");
30    let sandbox3 = SandboxBuilder::new("untrusted")
31        .memory_limit_str("64M")?
32        .cpu_limit_percent(10)
33        .max_pids(8)
34        .timeout(Duration::from_secs(5))
35        .seccomp_profile(sandbox_rs::SeccompProfile::Minimal)
36        .build()?;
37    println!("[*] Created: {}", sandbox3.id());
38    println!("[*] Root: {}\n", sandbox3.root().display());
39
40    println!("[*] All sandboxes created successfully!");
41    println!("[*] Note: Actual resource enforcement requires root permissions");
42
43    Ok(())
44}

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> 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, 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.