@@ -33,34 +33,26 @@ fn test_access() {
33
33
34
34
// ReadWrite
35
35
assert_eq ! (
36
- unsafe { VolatilePtr :: new_with_access( NonNull :: from( & mut val) , Access :: read_write( ) ) }
37
- . read( ) ,
36
+ unsafe { VolatilePtr :: new_read_write( NonNull :: from( & mut val) ) } . read( ) ,
38
37
42
39
38
) ;
40
- unsafe { VolatilePtr :: new_with_access ( NonNull :: from ( & mut val) , Access :: read_write ( ) ) }
41
- . write ( 50 ) ;
39
+ unsafe { VolatilePtr :: new_read_write ( NonNull :: from ( & mut val) ) } . write ( 50 ) ;
42
40
assert_eq ! ( val, 50 ) ;
43
- unsafe { VolatilePtr :: new_with_access ( NonNull :: from ( & mut val) , Access :: read_write ( ) ) }
44
- . update ( |i| * i += 1 ) ;
41
+ unsafe { VolatilePtr :: new_read_write ( NonNull :: from ( & mut val) ) } . update ( |i| * i += 1 ) ;
45
42
assert_eq ! ( val, 51 ) ;
46
43
47
44
// ReadOnly and WriteOnly
48
45
assert_eq ! (
49
- unsafe { VolatilePtr :: new_with_access( NonNull :: from( & mut val) , Access :: read_only( ) ) }
50
- . read( ) ,
46
+ unsafe { VolatilePtr :: new_read_only( NonNull :: from( & mut val) ) } . read( ) ,
51
47
51
52
48
) ;
53
- unsafe { VolatilePtr :: new_with_access ( NonNull :: from ( & mut val) , Access :: write_only ( ) ) }
54
- . write ( 12 ) ;
49
+ unsafe { VolatilePtr :: new_write_only ( NonNull :: from ( & mut val) ) } . write ( 12 ) ;
55
50
assert_eq ! ( val, 12 ) ;
56
51
57
52
// Custom: safe read + safe write
58
53
{
59
- let access = Access {
60
- read : SafeAccess ,
61
- write : SafeAccess ,
62
- } ;
63
- let mut volatile = unsafe { VolatilePtr :: new_with_access ( NonNull :: from ( & mut val) , access) } ;
54
+ type Custom = Access < SafeAccess , SafeAccess > ;
55
+ let mut volatile = unsafe { VolatilePtr :: new_generic :: < Custom > ( NonNull :: from ( & mut val) ) } ;
64
56
let random: i32 = rand:: random ( ) ;
65
57
volatile. write ( i64:: from ( random) ) ;
66
58
assert_eq ! ( volatile. read( ) , i64 :: from( random) ) ;
@@ -71,11 +63,8 @@ fn test_access() {
71
63
72
64
// Custom: safe read + unsafe write
73
65
{
74
- let access = Access {
75
- read : SafeAccess ,
76
- write : UnsafeAccess ,
77
- } ;
78
- let mut volatile = unsafe { VolatilePtr :: new_with_access ( NonNull :: from ( & mut val) , access) } ;
66
+ type Custom = Access < SafeAccess , UnsafeAccess > ;
67
+ let mut volatile = unsafe { VolatilePtr :: new_generic :: < Custom > ( NonNull :: from ( & mut val) ) } ;
79
68
let random: i32 = rand:: random ( ) ;
80
69
unsafe { volatile. write_unsafe ( i64:: from ( random) ) } ;
81
70
assert_eq ! ( volatile. read( ) , i64 :: from( random) ) ;
@@ -86,23 +75,17 @@ fn test_access() {
86
75
87
76
// Custom: safe read + no write
88
77
{
89
- let access = Access {
90
- read : SafeAccess ,
91
- write : NoAccess ,
92
- } ;
78
+ type Custom = Access < SafeAccess , NoAccess > ;
93
79
let random = rand:: random ( ) ;
94
80
val = random;
95
- let volatile = unsafe { VolatilePtr :: new_with_access ( NonNull :: from ( & mut val) , access ) } ;
81
+ let volatile = unsafe { VolatilePtr :: new_generic :: < Custom > ( NonNull :: from ( & mut val) ) } ;
96
82
assert_eq ! ( volatile. read( ) , i64 :: from( random) ) ;
97
83
}
98
84
99
85
// Custom: unsafe read + safe write
100
86
{
101
- let access = Access {
102
- read : UnsafeAccess ,
103
- write : SafeAccess ,
104
- } ;
105
- let mut volatile = unsafe { VolatilePtr :: new_with_access ( NonNull :: from ( & mut val) , access) } ;
87
+ type Custom = Access < UnsafeAccess , SafeAccess > ;
88
+ let mut volatile = unsafe { VolatilePtr :: new_generic :: < Custom > ( NonNull :: from ( & mut val) ) } ;
106
89
let random: i32 = rand:: random ( ) ;
107
90
volatile. write ( i64:: from ( random) ) ;
108
91
assert_eq ! ( unsafe { volatile. read_unsafe( ) } , i64 :: from( random) ) ;
0 commit comments