Sdl2Mt

Struct Sdl2Mt 

Source
pub struct Sdl2Mt(/* private fields */);

Implementations§

Source§

impl Sdl2Mt

Source

pub fn create_simple_window<IntoString: Into<String>>( &self, name: IntoString, width: u32, height: u32, ) -> Result<u32, UiThreadExited>

A quick, simple way to create a window. Just give it a name, width, and height.

This function executes synchronously. It will block until the window_creator function has completed.

§Panics

This function will panic if the Window or the Canvas build() functions do not succeed.

Examples found in repository?
examples/basic.rs (line 16)
12fn main() {
13    //sdlh is "sdl handle"
14    let sdlh = sdl2_mt::init();
15
16    let window = sdlh.create_simple_window("2D plot", 720, 720).unwrap();
17
18    // example of running arbitrary code on the UI thread
19    sdlh.run_on_ui_thread(Box::new(move |_sdl, windows| {
20        let canvas = windows.get_mut(&window).unwrap();
21        canvas.set_draw_color(Color::RGBA(128, 128, 128, 255));
22        canvas.clear();
23        canvas.present();
24    })).unwrap();
25
26    // create a channel we can use to easily break the loop
27    // from inside the closure.
28    let (tx, rx) = mpsc::channel();
29    while rx.try_recv().is_err() {
30        let tx = tx.clone();
31
32        // handle any new UI events that have happened
33        sdlh.handle_ui_events(Box::new(move |_sdl, windows, event| {
34            match event {
35                &Quit { .. } | &KeyDown { keycode: Some(Keycode::Escape), .. } => {
36                    // send a message to rx to cancel the loop
37                    tx.send(()).unwrap();
38                },
39
40                &KeyDown { keycode: Some(keycode), .. } => {
41                    use sdl2_mt::video::WindowPos::Positioned;
42                    let mut canvas = windows.get_mut(&window).unwrap();
43                    let (mut x, mut y) = canvas.window().position();
44                    match keycode {
45                        Keycode::Up    => y -= 5,
46                        Keycode::Down  => y += 5,
47                        Keycode::Left  => x -= 5,
48                        Keycode::Right => x += 5,
49                        _ => {}
50                    }
51                    canvas.window_mut().set_position(Positioned(x), Positioned(y));
52                },
53
54                &Window { win_event: WindowEvent::Resized(new_w, new_h), .. } => {
55                    let mut canvas = windows.get_mut(&window).unwrap();
56                    canvas.set_draw_color(Color::RGBA(128, (new_h % 256) as u8, (new_w % 256) as u8, 255));
57                    canvas.clear();
58                    canvas.present();
59                },
60                
61                // false means "this event handler function did not handle this event"
62                // in a multithreaded application, you might have an event handler per window.
63                // this makes it easier to juggle events between handlers.
64                _ => return false
65            }
66            // true means we handled this event
67            true
68        })).unwrap();
69
70        // keep the CPU usage down
71        sleep(Duration::from_millis(15));
72    }
73
74    // not strictly necessary, since when the main thread exits in Rust the entire program is killed.
75    // the exit() function has the effect of terminating the SDL2 UI thread.
76    sdlh.exit().unwrap();
77}
Source

pub fn create_window( &self, window_creator: Box<dyn FnMut(&mut Sdl, &mut VideoSubsystem) -> Option<WindowCanvas> + Send>, ) -> Result<Option<u32>, UiThreadExited>

Executes a window_creator function that accepts &mut VideoSubsystem and returns an Option. If Some(window), it will be added to a HashMap, hashing on the window’s ID, which will then be returned here. If None, None will be returned here.

This function executes synchronously. It will block until the window_creator function has completed.

Examples found in repository?
examples/custom_create_window.rs (lines 18-30)
12fn main() {
13    //sdlh is "sdl handle"
14    let sdlh = sdl2_mt::init();
15
16    // create_window() allows you to run arbitrary code to create a window
17    // and then return the drawable Canvas from that window.
18    let window = sdlh.create_window(Box::new(|_sdl, video_subsystem| {
19        let canvas = video_subsystem.window("2D plot", 720, 720)
20            .position_centered()
21            .resizable()
22            .build()
23            .unwrap()
24            .into_canvas()
25            .software()
26            .build()
27            .unwrap();
28        
29        Some(canvas)
30    })).unwrap().unwrap();
31
32    sleep(Duration::from_millis(20));
33
34    // example of running arbitrary code on the UI thread
35    sdlh.run_on_ui_thread(Box::new(move |_sdl, windows| {
36        let canvas = windows.get_mut(&window).unwrap();
37        canvas.set_draw_color(Color::RGBA(128, 128, 128, 255));
38        canvas.clear();
39        canvas.present();
40    })).unwrap();
41
42    // create a channel we can use to easily break the loop
43    // from inside the closure.
44    let (tx, rx) = mpsc::channel();
45    while rx.try_recv().is_err() {
46        let tx = tx.clone();
47
48        // handle any new UI events that have happened
49        sdlh.handle_ui_events(Box::new(move |_sdl, windows, event| {
50            match event {
51                &Quit { .. } | &KeyDown { keycode: Some(Keycode::Escape), .. } => {
52                    // send a message to rx to cancel the loop
53                    tx.send(()).unwrap();
54                },
55
56                &KeyDown { keycode: Some(keycode), .. } => {
57                    use sdl2_mt::video::WindowPos::Positioned;
58                    let mut canvas = windows.get_mut(&window).unwrap();
59                    let (mut x, mut y) = canvas.window().position();
60                    match keycode {
61                        Keycode::Up    => y -= 5,
62                        Keycode::Down  => y += 5,
63                        Keycode::Left  => x -= 5,
64                        Keycode::Right => x += 5,
65                        _ => {}
66                    }
67                    canvas.window_mut().set_position(Positioned(x), Positioned(y));
68                },
69
70                &Window { win_event: WindowEvent::Resized(new_w, new_h), .. } => {
71                    let mut canvas = windows.get_mut(&window).unwrap();
72                    canvas.set_draw_color(Color::RGBA(128, (new_h % 256) as u8, (new_w % 256) as u8, 255));
73                    canvas.clear();
74                    canvas.present();
75                },
76                // false means "this event handler function did not handle this event"
77                // in a multithreaded application, you might have an event handler per window.
78                // this makes it easier to juggle events between handlers.
79                _ => return false
80            }
81            // true means we handled this event
82            true
83        })).unwrap();
84
85        // keep the CPU usage down
86        sleep(Duration::from_millis(15));
87    }
88
89    // not strictly necessary, since when the main thread exits in Rust the entire program is killed.
90    // the exit() function has the effect of terminating the SDL2 UI thread.
91    sdlh.exit().unwrap();
92}
Source

pub fn run_on_ui_thread( &self, lambda: Box<dyn FnMut(&mut Sdl, &mut HashMap<u32, WindowCanvas>) + Send>, ) -> Result<(), UiThreadExited>

This function executes asynchronously. It will not block the calling thread.

Examples found in repository?
examples/basic.rs (lines 19-24)
12fn main() {
13    //sdlh is "sdl handle"
14    let sdlh = sdl2_mt::init();
15
16    let window = sdlh.create_simple_window("2D plot", 720, 720).unwrap();
17
18    // example of running arbitrary code on the UI thread
19    sdlh.run_on_ui_thread(Box::new(move |_sdl, windows| {
20        let canvas = windows.get_mut(&window).unwrap();
21        canvas.set_draw_color(Color::RGBA(128, 128, 128, 255));
22        canvas.clear();
23        canvas.present();
24    })).unwrap();
25
26    // create a channel we can use to easily break the loop
27    // from inside the closure.
28    let (tx, rx) = mpsc::channel();
29    while rx.try_recv().is_err() {
30        let tx = tx.clone();
31
32        // handle any new UI events that have happened
33        sdlh.handle_ui_events(Box::new(move |_sdl, windows, event| {
34            match event {
35                &Quit { .. } | &KeyDown { keycode: Some(Keycode::Escape), .. } => {
36                    // send a message to rx to cancel the loop
37                    tx.send(()).unwrap();
38                },
39
40                &KeyDown { keycode: Some(keycode), .. } => {
41                    use sdl2_mt::video::WindowPos::Positioned;
42                    let mut canvas = windows.get_mut(&window).unwrap();
43                    let (mut x, mut y) = canvas.window().position();
44                    match keycode {
45                        Keycode::Up    => y -= 5,
46                        Keycode::Down  => y += 5,
47                        Keycode::Left  => x -= 5,
48                        Keycode::Right => x += 5,
49                        _ => {}
50                    }
51                    canvas.window_mut().set_position(Positioned(x), Positioned(y));
52                },
53
54                &Window { win_event: WindowEvent::Resized(new_w, new_h), .. } => {
55                    let mut canvas = windows.get_mut(&window).unwrap();
56                    canvas.set_draw_color(Color::RGBA(128, (new_h % 256) as u8, (new_w % 256) as u8, 255));
57                    canvas.clear();
58                    canvas.present();
59                },
60                
61                // false means "this event handler function did not handle this event"
62                // in a multithreaded application, you might have an event handler per window.
63                // this makes it easier to juggle events between handlers.
64                _ => return false
65            }
66            // true means we handled this event
67            true
68        })).unwrap();
69
70        // keep the CPU usage down
71        sleep(Duration::from_millis(15));
72    }
73
74    // not strictly necessary, since when the main thread exits in Rust the entire program is killed.
75    // the exit() function has the effect of terminating the SDL2 UI thread.
76    sdlh.exit().unwrap();
77}
More examples
Hide additional examples
examples/custom_create_window.rs (lines 35-40)
12fn main() {
13    //sdlh is "sdl handle"
14    let sdlh = sdl2_mt::init();
15
16    // create_window() allows you to run arbitrary code to create a window
17    // and then return the drawable Canvas from that window.
18    let window = sdlh.create_window(Box::new(|_sdl, video_subsystem| {
19        let canvas = video_subsystem.window("2D plot", 720, 720)
20            .position_centered()
21            .resizable()
22            .build()
23            .unwrap()
24            .into_canvas()
25            .software()
26            .build()
27            .unwrap();
28        
29        Some(canvas)
30    })).unwrap().unwrap();
31
32    sleep(Duration::from_millis(20));
33
34    // example of running arbitrary code on the UI thread
35    sdlh.run_on_ui_thread(Box::new(move |_sdl, windows| {
36        let canvas = windows.get_mut(&window).unwrap();
37        canvas.set_draw_color(Color::RGBA(128, 128, 128, 255));
38        canvas.clear();
39        canvas.present();
40    })).unwrap();
41
42    // create a channel we can use to easily break the loop
43    // from inside the closure.
44    let (tx, rx) = mpsc::channel();
45    while rx.try_recv().is_err() {
46        let tx = tx.clone();
47
48        // handle any new UI events that have happened
49        sdlh.handle_ui_events(Box::new(move |_sdl, windows, event| {
50            match event {
51                &Quit { .. } | &KeyDown { keycode: Some(Keycode::Escape), .. } => {
52                    // send a message to rx to cancel the loop
53                    tx.send(()).unwrap();
54                },
55
56                &KeyDown { keycode: Some(keycode), .. } => {
57                    use sdl2_mt::video::WindowPos::Positioned;
58                    let mut canvas = windows.get_mut(&window).unwrap();
59                    let (mut x, mut y) = canvas.window().position();
60                    match keycode {
61                        Keycode::Up    => y -= 5,
62                        Keycode::Down  => y += 5,
63                        Keycode::Left  => x -= 5,
64                        Keycode::Right => x += 5,
65                        _ => {}
66                    }
67                    canvas.window_mut().set_position(Positioned(x), Positioned(y));
68                },
69
70                &Window { win_event: WindowEvent::Resized(new_w, new_h), .. } => {
71                    let mut canvas = windows.get_mut(&window).unwrap();
72                    canvas.set_draw_color(Color::RGBA(128, (new_h % 256) as u8, (new_w % 256) as u8, 255));
73                    canvas.clear();
74                    canvas.present();
75                },
76                // false means "this event handler function did not handle this event"
77                // in a multithreaded application, you might have an event handler per window.
78                // this makes it easier to juggle events between handlers.
79                _ => return false
80            }
81            // true means we handled this event
82            true
83        })).unwrap();
84
85        // keep the CPU usage down
86        sleep(Duration::from_millis(15));
87    }
88
89    // not strictly necessary, since when the main thread exits in Rust the entire program is killed.
90    // the exit() function has the effect of terminating the SDL2 UI thread.
91    sdlh.exit().unwrap();
92}
Source

pub fn handle_ui_events( &self, event_handler: Box<dyn FnMut(&mut Sdl, &mut HashMap<u32, WindowCanvas>, &Event) -> bool + Send>, ) -> Result<(), UiThreadExited>

Executes an event_handler function.

This function executes synchronously. It will block until the event_handler function has completed.

Examples found in repository?
examples/basic.rs (lines 33-68)
12fn main() {
13    //sdlh is "sdl handle"
14    let sdlh = sdl2_mt::init();
15
16    let window = sdlh.create_simple_window("2D plot", 720, 720).unwrap();
17
18    // example of running arbitrary code on the UI thread
19    sdlh.run_on_ui_thread(Box::new(move |_sdl, windows| {
20        let canvas = windows.get_mut(&window).unwrap();
21        canvas.set_draw_color(Color::RGBA(128, 128, 128, 255));
22        canvas.clear();
23        canvas.present();
24    })).unwrap();
25
26    // create a channel we can use to easily break the loop
27    // from inside the closure.
28    let (tx, rx) = mpsc::channel();
29    while rx.try_recv().is_err() {
30        let tx = tx.clone();
31
32        // handle any new UI events that have happened
33        sdlh.handle_ui_events(Box::new(move |_sdl, windows, event| {
34            match event {
35                &Quit { .. } | &KeyDown { keycode: Some(Keycode::Escape), .. } => {
36                    // send a message to rx to cancel the loop
37                    tx.send(()).unwrap();
38                },
39
40                &KeyDown { keycode: Some(keycode), .. } => {
41                    use sdl2_mt::video::WindowPos::Positioned;
42                    let mut canvas = windows.get_mut(&window).unwrap();
43                    let (mut x, mut y) = canvas.window().position();
44                    match keycode {
45                        Keycode::Up    => y -= 5,
46                        Keycode::Down  => y += 5,
47                        Keycode::Left  => x -= 5,
48                        Keycode::Right => x += 5,
49                        _ => {}
50                    }
51                    canvas.window_mut().set_position(Positioned(x), Positioned(y));
52                },
53
54                &Window { win_event: WindowEvent::Resized(new_w, new_h), .. } => {
55                    let mut canvas = windows.get_mut(&window).unwrap();
56                    canvas.set_draw_color(Color::RGBA(128, (new_h % 256) as u8, (new_w % 256) as u8, 255));
57                    canvas.clear();
58                    canvas.present();
59                },
60                
61                // false means "this event handler function did not handle this event"
62                // in a multithreaded application, you might have an event handler per window.
63                // this makes it easier to juggle events between handlers.
64                _ => return false
65            }
66            // true means we handled this event
67            true
68        })).unwrap();
69
70        // keep the CPU usage down
71        sleep(Duration::from_millis(15));
72    }
73
74    // not strictly necessary, since when the main thread exits in Rust the entire program is killed.
75    // the exit() function has the effect of terminating the SDL2 UI thread.
76    sdlh.exit().unwrap();
77}
More examples
Hide additional examples
examples/custom_create_window.rs (lines 49-83)
12fn main() {
13    //sdlh is "sdl handle"
14    let sdlh = sdl2_mt::init();
15
16    // create_window() allows you to run arbitrary code to create a window
17    // and then return the drawable Canvas from that window.
18    let window = sdlh.create_window(Box::new(|_sdl, video_subsystem| {
19        let canvas = video_subsystem.window("2D plot", 720, 720)
20            .position_centered()
21            .resizable()
22            .build()
23            .unwrap()
24            .into_canvas()
25            .software()
26            .build()
27            .unwrap();
28        
29        Some(canvas)
30    })).unwrap().unwrap();
31
32    sleep(Duration::from_millis(20));
33
34    // example of running arbitrary code on the UI thread
35    sdlh.run_on_ui_thread(Box::new(move |_sdl, windows| {
36        let canvas = windows.get_mut(&window).unwrap();
37        canvas.set_draw_color(Color::RGBA(128, 128, 128, 255));
38        canvas.clear();
39        canvas.present();
40    })).unwrap();
41
42    // create a channel we can use to easily break the loop
43    // from inside the closure.
44    let (tx, rx) = mpsc::channel();
45    while rx.try_recv().is_err() {
46        let tx = tx.clone();
47
48        // handle any new UI events that have happened
49        sdlh.handle_ui_events(Box::new(move |_sdl, windows, event| {
50            match event {
51                &Quit { .. } | &KeyDown { keycode: Some(Keycode::Escape), .. } => {
52                    // send a message to rx to cancel the loop
53                    tx.send(()).unwrap();
54                },
55
56                &KeyDown { keycode: Some(keycode), .. } => {
57                    use sdl2_mt::video::WindowPos::Positioned;
58                    let mut canvas = windows.get_mut(&window).unwrap();
59                    let (mut x, mut y) = canvas.window().position();
60                    match keycode {
61                        Keycode::Up    => y -= 5,
62                        Keycode::Down  => y += 5,
63                        Keycode::Left  => x -= 5,
64                        Keycode::Right => x += 5,
65                        _ => {}
66                    }
67                    canvas.window_mut().set_position(Positioned(x), Positioned(y));
68                },
69
70                &Window { win_event: WindowEvent::Resized(new_w, new_h), .. } => {
71                    let mut canvas = windows.get_mut(&window).unwrap();
72                    canvas.set_draw_color(Color::RGBA(128, (new_h % 256) as u8, (new_w % 256) as u8, 255));
73                    canvas.clear();
74                    canvas.present();
75                },
76                // false means "this event handler function did not handle this event"
77                // in a multithreaded application, you might have an event handler per window.
78                // this makes it easier to juggle events between handlers.
79                _ => return false
80            }
81            // true means we handled this event
82            true
83        })).unwrap();
84
85        // keep the CPU usage down
86        sleep(Duration::from_millis(15));
87    }
88
89    // not strictly necessary, since when the main thread exits in Rust the entire program is killed.
90    // the exit() function has the effect of terminating the SDL2 UI thread.
91    sdlh.exit().unwrap();
92}
Source

pub fn exit(self) -> Result<(), UiThreadExited>

Terminates the UI thread. Not strictly necessary if the program will exit anyways, such as when the main program thread returns from main.

Examples found in repository?
examples/basic.rs (line 76)
12fn main() {
13    //sdlh is "sdl handle"
14    let sdlh = sdl2_mt::init();
15
16    let window = sdlh.create_simple_window("2D plot", 720, 720).unwrap();
17
18    // example of running arbitrary code on the UI thread
19    sdlh.run_on_ui_thread(Box::new(move |_sdl, windows| {
20        let canvas = windows.get_mut(&window).unwrap();
21        canvas.set_draw_color(Color::RGBA(128, 128, 128, 255));
22        canvas.clear();
23        canvas.present();
24    })).unwrap();
25
26    // create a channel we can use to easily break the loop
27    // from inside the closure.
28    let (tx, rx) = mpsc::channel();
29    while rx.try_recv().is_err() {
30        let tx = tx.clone();
31
32        // handle any new UI events that have happened
33        sdlh.handle_ui_events(Box::new(move |_sdl, windows, event| {
34            match event {
35                &Quit { .. } | &KeyDown { keycode: Some(Keycode::Escape), .. } => {
36                    // send a message to rx to cancel the loop
37                    tx.send(()).unwrap();
38                },
39
40                &KeyDown { keycode: Some(keycode), .. } => {
41                    use sdl2_mt::video::WindowPos::Positioned;
42                    let mut canvas = windows.get_mut(&window).unwrap();
43                    let (mut x, mut y) = canvas.window().position();
44                    match keycode {
45                        Keycode::Up    => y -= 5,
46                        Keycode::Down  => y += 5,
47                        Keycode::Left  => x -= 5,
48                        Keycode::Right => x += 5,
49                        _ => {}
50                    }
51                    canvas.window_mut().set_position(Positioned(x), Positioned(y));
52                },
53
54                &Window { win_event: WindowEvent::Resized(new_w, new_h), .. } => {
55                    let mut canvas = windows.get_mut(&window).unwrap();
56                    canvas.set_draw_color(Color::RGBA(128, (new_h % 256) as u8, (new_w % 256) as u8, 255));
57                    canvas.clear();
58                    canvas.present();
59                },
60                
61                // false means "this event handler function did not handle this event"
62                // in a multithreaded application, you might have an event handler per window.
63                // this makes it easier to juggle events between handlers.
64                _ => return false
65            }
66            // true means we handled this event
67            true
68        })).unwrap();
69
70        // keep the CPU usage down
71        sleep(Duration::from_millis(15));
72    }
73
74    // not strictly necessary, since when the main thread exits in Rust the entire program is killed.
75    // the exit() function has the effect of terminating the SDL2 UI thread.
76    sdlh.exit().unwrap();
77}
More examples
Hide additional examples
examples/custom_create_window.rs (line 91)
12fn main() {
13    //sdlh is "sdl handle"
14    let sdlh = sdl2_mt::init();
15
16    // create_window() allows you to run arbitrary code to create a window
17    // and then return the drawable Canvas from that window.
18    let window = sdlh.create_window(Box::new(|_sdl, video_subsystem| {
19        let canvas = video_subsystem.window("2D plot", 720, 720)
20            .position_centered()
21            .resizable()
22            .build()
23            .unwrap()
24            .into_canvas()
25            .software()
26            .build()
27            .unwrap();
28        
29        Some(canvas)
30    })).unwrap().unwrap();
31
32    sleep(Duration::from_millis(20));
33
34    // example of running arbitrary code on the UI thread
35    sdlh.run_on_ui_thread(Box::new(move |_sdl, windows| {
36        let canvas = windows.get_mut(&window).unwrap();
37        canvas.set_draw_color(Color::RGBA(128, 128, 128, 255));
38        canvas.clear();
39        canvas.present();
40    })).unwrap();
41
42    // create a channel we can use to easily break the loop
43    // from inside the closure.
44    let (tx, rx) = mpsc::channel();
45    while rx.try_recv().is_err() {
46        let tx = tx.clone();
47
48        // handle any new UI events that have happened
49        sdlh.handle_ui_events(Box::new(move |_sdl, windows, event| {
50            match event {
51                &Quit { .. } | &KeyDown { keycode: Some(Keycode::Escape), .. } => {
52                    // send a message to rx to cancel the loop
53                    tx.send(()).unwrap();
54                },
55
56                &KeyDown { keycode: Some(keycode), .. } => {
57                    use sdl2_mt::video::WindowPos::Positioned;
58                    let mut canvas = windows.get_mut(&window).unwrap();
59                    let (mut x, mut y) = canvas.window().position();
60                    match keycode {
61                        Keycode::Up    => y -= 5,
62                        Keycode::Down  => y += 5,
63                        Keycode::Left  => x -= 5,
64                        Keycode::Right => x += 5,
65                        _ => {}
66                    }
67                    canvas.window_mut().set_position(Positioned(x), Positioned(y));
68                },
69
70                &Window { win_event: WindowEvent::Resized(new_w, new_h), .. } => {
71                    let mut canvas = windows.get_mut(&window).unwrap();
72                    canvas.set_draw_color(Color::RGBA(128, (new_h % 256) as u8, (new_w % 256) as u8, 255));
73                    canvas.clear();
74                    canvas.present();
75                },
76                // false means "this event handler function did not handle this event"
77                // in a multithreaded application, you might have an event handler per window.
78                // this makes it easier to juggle events between handlers.
79                _ => return false
80            }
81            // true means we handled this event
82            true
83        })).unwrap();
84
85        // keep the CPU usage down
86        sleep(Duration::from_millis(15));
87    }
88
89    // not strictly necessary, since when the main thread exits in Rust the entire program is killed.
90    // the exit() function has the effect of terminating the SDL2 UI thread.
91    sdlh.exit().unwrap();
92}

Trait Implementations§

Source§

impl Clone for Sdl2Mt

Source§

fn clone(&self) -> Sdl2Mt

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl Freeze for Sdl2Mt

§

impl RefUnwindSafe for Sdl2Mt

§

impl Send for Sdl2Mt

§

impl Sync for Sdl2Mt

§

impl Unpin for Sdl2Mt

§

impl UnwindSafe for Sdl2Mt

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

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

Source§

type Error = <U as TryFrom<T>>::Error

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

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.