@@ -33,34 +33,26 @@ fn test_access() {
3333
3434 // ReadWrite
3535 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( ) ,
3837 42
3938 ) ;
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 ) ;
4240 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 ) ;
4542 assert_eq ! ( val, 51 ) ;
4643
4744 // ReadOnly and WriteOnly
4845 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( ) ,
5147 51
5248 ) ;
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 ) ;
5550 assert_eq ! ( val, 12 ) ;
5651
5752 // Custom: safe read + safe write
5853 {
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) ) } ;
6456 let random: i32 = rand:: random ( ) ;
6557 volatile. write ( i64:: from ( random) ) ;
6658 assert_eq ! ( volatile. read( ) , i64 :: from( random) ) ;
@@ -71,11 +63,8 @@ fn test_access() {
7163
7264 // Custom: safe read + unsafe write
7365 {
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) ) } ;
7968 let random: i32 = rand:: random ( ) ;
8069 unsafe { volatile. write_unsafe ( i64:: from ( random) ) } ;
8170 assert_eq ! ( volatile. read( ) , i64 :: from( random) ) ;
@@ -86,23 +75,17 @@ fn test_access() {
8675
8776 // Custom: safe read + no write
8877 {
89- let access = Access {
90- read : SafeAccess ,
91- write : NoAccess ,
92- } ;
78+ type Custom = Access < SafeAccess , NoAccess > ;
9379 let random = rand:: random ( ) ;
9480 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) ) } ;
9682 assert_eq ! ( volatile. read( ) , i64 :: from( random) ) ;
9783 }
9884
9985 // Custom: unsafe read + safe write
10086 {
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) ) } ;
10689 let random: i32 = rand:: random ( ) ;
10790 volatile. write ( i64:: from ( random) ) ;
10891 assert_eq ! ( unsafe { volatile. read_unsafe( ) } , i64 :: from( random) ) ;
0 commit comments