File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -20,6 +20,17 @@ config SAMPLE_RUST_MINIMAL
2020
2121 If unsure, say N.
2222
23+ config SAMPLE_RUST_INPLACE
24+ tristate "Minimal in-place"
25+ help
26+ This option builds the Rust minimal module with in-place
27+ initialisation.
28+
29+ To compile this as a module, choose M here:
30+ the module will be called rust_inplace.
31+
32+ If unsure, say N.
33+
2334config SAMPLE_RUST_PRINT
2435 tristate "Printing macros"
2536 help
Original file line number Diff line number Diff line change 11# SPDX-License-Identifier: GPL-2.0
22
33obj-$(CONFIG_SAMPLE_RUST_MINIMAL) += rust_minimal.o
4+ obj-$(CONFIG_SAMPLE_RUST_INPLACE) += rust_inplace.o
45obj-$(CONFIG_SAMPLE_RUST_PRINT) += rust_print.o
56
67subdir-$(CONFIG_SAMPLE_RUST_HOSTPROGS) += hostprogs
Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: GPL-2.0
2+
3+ //! Rust minimal in-place sample.
4+
5+ use kernel:: prelude:: * ;
6+
7+ module ! {
8+ type : RustInPlace ,
9+ name: "rust_inplace" ,
10+ author: "Rust for Linux Contributors" ,
11+ description: "Rust minimal in-place sample" ,
12+ license: "GPL" ,
13+ }
14+
15+ #[ pin_data( PinnedDrop ) ]
16+ struct RustInPlace {
17+ numbers : Vec < i32 > ,
18+ }
19+
20+ impl kernel:: InPlaceModule for RustInPlace {
21+ type Init = impl PinInit < Self , Error > ;
22+ fn init ( _module : & ' static ThisModule ) -> Self :: Init {
23+ pr_info ! ( "Rust minimal sample (init)\n " ) ;
24+ pr_info ! ( "Am I built-in? {}\n " , !cfg!( MODULE ) ) ;
25+ try_pin_init ! ( Self {
26+ numbers: {
27+ let mut numbers = Vec :: new( ) ;
28+ numbers. try_push( 72 ) ?;
29+ numbers. try_push( 108 ) ?;
30+ numbers. try_push( 200 ) ?;
31+ numbers
32+ } ,
33+ } )
34+ }
35+ }
36+
37+ #[ pinned_drop]
38+ impl PinnedDrop for RustInPlace {
39+ fn drop ( self : Pin < & mut Self > ) {
40+ pr_info ! ( "My numbers are {:?}\n " , self . numbers) ;
41+ pr_info ! ( "Rust minimal inplace sample (exit)\n " ) ;
42+ }
43+ }
You can’t perform that action at this time.
0 commit comments