File tree Expand file tree Collapse file tree 4 files changed +55
-1
lines changed Expand file tree Collapse file tree 4 files changed +55
-1
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,17 @@ config SAMPLE_RUST_MINIMAL
20
20
21
21
If unsure, say N.
22
22
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
+
23
34
config SAMPLE_RUST_PRINT
24
35
tristate "Printing macros"
25
36
help
Original file line number Diff line number Diff line change 1
1
# SPDX-License-Identifier: GPL-2.0
2
2
3
3
obj-$(CONFIG_SAMPLE_RUST_MINIMAL) += rust_minimal.o
4
+ obj-$(CONFIG_SAMPLE_RUST_INPLACE) += rust_inplace.o
4
5
obj-$(CONFIG_SAMPLE_RUST_PRINT) += rust_print.o
5
6
6
7
subdir-$(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
+ fn init ( _module : & ' static ThisModule ) -> impl PinInit < Self , Error > {
22
+ pr_info ! ( "Rust minimal sample (init)\n " ) ;
23
+ pr_info ! ( "Am I built-in? {}\n " , !cfg!( MODULE ) ) ;
24
+ try_pin_init ! ( Self {
25
+ numbers: {
26
+ let mut numbers = Vec :: new( ) ;
27
+ numbers. try_push( 72 ) ?;
28
+ numbers. try_push( 108 ) ?;
29
+ numbers. try_push( 200 ) ?;
30
+ numbers
31
+ } ,
32
+ } )
33
+ }
34
+ }
35
+
36
+ #[ pinned_drop]
37
+ impl PinnedDrop for RustInPlace {
38
+ fn drop ( self : Pin < & mut Self > ) {
39
+ pr_info ! ( "My numbers are {:?}\n " , self . numbers) ;
40
+ pr_info ! ( "Rust minimal inplace sample (exit)\n " ) ;
41
+ }
42
+ }
Original file line number Diff line number Diff line change @@ -262,7 +262,7 @@ $(obj)/%.lst: $(src)/%.c FORCE
262
262
# Compile Rust sources (.rs)
263
263
# ---------------------------------------------------------------------------
264
264
265
- rust_allowed_features := new_uninit,impl_trait_in_assoc_type
265
+ rust_allowed_features := new_uninit,return_position_impl_trait_in_trait
266
266
267
267
# `--out-dir` is required to avoid temporaries being created by `rustc` in the
268
268
# current working directory, which may be not accessible in the out-of-tree
You can’t perform that action at this time.
0 commit comments