File tree Expand file tree Collapse file tree 3 files changed +10
-14
lines changed Expand file tree Collapse file tree 3 files changed +10
-14
lines changed Original file line number Diff line number Diff line change @@ -520,6 +520,12 @@ pub trait FileOpener<T: ?Sized>: FileOperations {
520
520
fn open ( context : & T ) -> KernelResult < Self :: Wrapper > ;
521
521
}
522
522
523
+ impl < T : FileOperations < Wrapper = Box < T > > + Default > FileOpener < ( ) > for T {
524
+ fn open ( _: & ( ) ) -> KernelResult < Self :: Wrapper > {
525
+ Ok ( Box :: try_new ( T :: default ( ) ) ?)
526
+ }
527
+ }
528
+
523
529
/// Corresponds to the kernel's `struct file_operations`.
524
530
///
525
531
/// You implement this trait whenever you would create a `struct file_operations`.
@@ -532,7 +538,7 @@ pub trait FileOperations: Send + Sync + Sized {
532
538
const TO_USE : ToUse ;
533
539
534
540
/// The pointer type that will be used to hold ourselves.
535
- type Wrapper : PointerWrapper < Self > ;
541
+ type Wrapper : PointerWrapper < Self > = Box < Self > ;
536
542
537
543
/// Cleans up after the last reference to the file goes away.
538
544
///
Original file line number Diff line number Diff line change 15
15
#![ feature(
16
16
allocator_api,
17
17
alloc_error_handler,
18
+ associated_type_defaults,
18
19
const_fn,
19
20
const_mut_refs,
20
21
const_panic,
Original file line number Diff line number Diff line change 8
8
use alloc:: boxed:: Box ;
9
9
use core:: pin:: Pin ;
10
10
use kernel:: prelude:: * ;
11
- use kernel:: {
12
- chrdev, cstr,
13
- file_operations:: { FileOpener , FileOperations } ,
14
- } ;
11
+ use kernel:: { chrdev, cstr, file_operations:: FileOperations } ;
15
12
16
13
module ! {
17
14
type : RustChrdev ,
@@ -23,18 +20,10 @@ module! {
23
20
} ,
24
21
}
25
22
23
+ #[ derive( Default ) ]
26
24
struct RustFile ;
27
25
28
- impl FileOpener < ( ) > for RustFile {
29
- fn open ( _ctx : & ( ) ) -> KernelResult < Self :: Wrapper > {
30
- pr_info ! ( "rust file was opened!\n " ) ;
31
- Ok ( Box :: try_new ( Self ) ?)
32
- }
33
- }
34
-
35
26
impl FileOperations for RustFile {
36
- type Wrapper = Box < Self > ;
37
-
38
27
kernel:: declare_file_operations!( ) ;
39
28
}
40
29
You can’t perform that action at this time.
0 commit comments