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
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+ 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
262262# Compile Rust sources (.rs)
263263# ---------------------------------------------------------------------------
264264
265- rust_allowed_features := new_uninit,impl_trait_in_assoc_type
265+ rust_allowed_features := new_uninit,return_position_impl_trait_in_trait
266266
267267# `--out-dir` is required to avoid temporaries being created by `rustc` in the
268268# 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