2
2
//!
3
3
//! # Example
4
4
//! ```rust,ignore
5
- //! let s: Scm<UnspecifiedSpec > = Guile::eval("\"test string...\"");
5
+ //! let s: Scm<Untyped > = Guile::eval("\"test string...\"");
6
6
//! let s: Scm<StringSpec> = s.into_string().unwrap();
7
7
//! let s: String = s.to_string();
8
8
//! assert_eq!(s, "test string...");
@@ -36,42 +36,25 @@ $ ($ e : tt) *
36
36
$ ( $ e) *
37
37
}
38
38
} extern crate guile_rs_sys;
39
+ mod untyped;
40
+ mod bool;
41
+ mod string;
42
+ mod numeric;
43
+ pub use self :: untyped :: Untyped ;
44
+ pub use self :: bool :: Bool ;
45
+ pub use self :: string :: String ;
46
+ pub use self :: numeric :: * ;
39
47
use self :: guile_rs_sys :: * ;
40
48
use std :: ffi :: CString ;
41
49
use std :: marker :: PhantomData ;
42
50
use std :: ptr;
43
- use std :: ops :: Not ;
44
51
use std :: mem :: {
45
52
transmute , forget
46
53
} ;
47
54
use std :: collections :: VecDeque ;
48
55
use libc;
49
- mod numeric;
50
56
pub trait TypeSpec {
51
- } pub trait Numeric : TypeSpec {
52
- } # [ derive ( Debug ) ] pub struct UnspecifiedSpec ;
53
- impl TypeSpec for UnspecifiedSpec {
54
- } # [ derive ( Debug ) ] pub struct BoolSpec ;
55
- impl TypeSpec for BoolSpec {
56
- } /// See [spec implementation](struct.Scm.html#impl-4)
57
- # [ derive ( Debug ) ] pub struct NumericSpec ;
58
- impl TypeSpec for NumericSpec {
59
- } impl Numeric for NumericSpec {
60
- } /// See [spec implementation](struct.Scm.html#impl-5)
61
- # [ derive ( Debug ) ] pub struct IntSpec ;
62
- impl TypeSpec for IntSpec {
63
- } impl Numeric for IntSpec {
64
- } # [ derive ( Debug ) ] pub struct RationalSpec ;
65
- impl TypeSpec for RationalSpec {
66
- } impl Numeric for RationalSpec {
67
- } # [ derive ( Debug ) ] pub struct RealSpec ;
68
- impl TypeSpec for RealSpec {
69
- } impl Numeric for RealSpec {
70
- } # [ derive ( Debug ) ] pub struct ComplexSpec ;
71
- impl TypeSpec for ComplexSpec {
72
- } impl Numeric for ComplexSpec {
73
- } # [ derive ( Debug ) ] pub struct StringSpec ;
74
- impl TypeSpec for StringSpec {
57
+ } pub trait NumericSpec : TypeSpec {
75
58
} # [ derive ( Debug ) ] pub struct SymbolSpec ;
76
59
impl TypeSpec for SymbolSpec {
77
60
} # [ derive ( Debug ) ] pub struct PairSpec ;
@@ -106,13 +89,13 @@ pub (crate) data : SCM , spec : PhantomData < TS >
106
89
Scm {
107
90
data , spec : PhantomData
108
91
}
109
- } # [ inline ] pub fn from_raw ( data : SCM ) -> Scm < UnspecifiedSpec > {
92
+ } # [ inline ] pub fn from_raw ( data : SCM ) -> Scm < Untyped > {
110
93
Scm :: _from_raw ( data)
111
94
} # [ inline ] pub unsafe fn into_raw ( self ) -> SCM {
112
95
self . data
113
96
} fn into_type < S : TypeSpec > ( self ) -> Scm < S > {
114
97
Scm :: _from_raw ( self . data )
115
- } # [ inline ] pub fn into_unspecified ( self ) -> Scm < UnspecifiedSpec > {
98
+ } # [ inline ] pub fn into_unspecified ( self ) -> Scm < Untyped > {
116
99
Scm :: into_type ( self )
117
100
} # [ inline ] pub fn as_bits ( & self ) -> scm_t_bits {
118
101
unsafe {
@@ -150,7 +133,7 @@ is_thing_p! (list_p => scm_list_p);
150
133
is_thing_p ! ( hash_table_p => scm_hash_table_p) ;
151
134
/// check for identity (`scm_eq_p`)
152
135
/// scheme operation: `eq?`
153
- # [ inline ] pub fn eq_p < OS : TypeSpec > ( & self , other : & Scm < OS > ) -> Scm < BoolSpec > {
136
+ # [ inline ] pub fn eq_p < OS : TypeSpec > ( & self , other : & Scm < OS > ) -> Scm < Bool > {
154
137
Scm :: _from_raw ( unsafe {
155
138
scm_eq_p ( self . data , other . data )
156
139
} )
@@ -250,10 +233,10 @@ vals . push_back (slot_c) ;
250
233
forget ( slot_types) ;
251
234
let slot_types_r : Box < Box < TypeList > > = Box :: from_raw ( slot_types_r) ;
252
235
drop ( slot_types_r) ;
253
- } pub fn new_type ( name : & Scm < StringSpec > , slot_names : & Scm < ListSpec > , slot_types : Box < TypeList > ) -> Self {
236
+ } pub fn new_type ( name : & Scm < self :: String > , slot_names : & Scm < ListSpec > , slot_types : Box < TypeList > ) -> Self {
254
237
let slot_types : Box < Box < TypeList > > = Box :: new ( slot_types) ;
255
238
let slot_types_r : * mut Box < TypeList > = Box :: into_raw ( slot_types) ;
256
- let slot_names : Scm < ListSpec > = Scm :: cons ( & Scm :: < StringSpec > :: from ( "types" ) , & slot_names) . into_list ( ) . unwrap ( ) ;
239
+ let slot_names : Scm < ListSpec > = Scm :: cons ( & Scm :: < self :: String > :: from ( "types" ) , & slot_names) . into_list ( ) . unwrap ( ) ;
257
240
Scm :: _from_raw ( unsafe {
258
241
scm_make_foreign_object_type ( name . data , slot_names . data , Some ( Scm :: finalizer) )
259
242
} )
@@ -270,8 +253,8 @@ FT :: as_struct_mut ()
270
253
} pub fn as_struct < ' a > ( ) -> & ' a FT :: Struct {
271
254
FT :: as_struct ( )
272
255
}
273
- } impl < N : Numeric > From < Scm < N > > for Scm < StringSpec > {
274
- fn from ( numeric : Scm < N > ) -> Scm < StringSpec > {
256
+ } impl < N : NumericSpec > From < Scm < N > > for Scm < self :: String > {
257
+ fn from ( numeric : Scm < N > ) -> Scm < self :: String > {
275
258
Self {
276
259
data : unsafe {
277
260
scm_number_to_string ( numeric . data , ptr :: null_mut ( ) )
@@ -281,72 +264,12 @@ scm_number_to_string (numeric . data , ptr :: null_mut ())
281
264
} pub trait TryAs < T , E > {
282
265
/// attemp to get `&self` as type `T`
283
266
fn try_as ( & self ) -> Result < T , E > ;
284
- } impl Scm < UnspecifiedSpec > {
285
- into_type ! ( into_bool , is_bool , BoolSpec ) ;
286
- into_type ! ( into_string , is_string , StringSpec ) ;
287
- into_type ! ( into_integer , is_integer , IntSpec ) ;
288
- into_type ! ( into_symbol , is_symbol , SymbolSpec ) ;
289
- into_type ! ( into_pair , is_pair , PairSpec ) ;
290
- into_type ! ( into_list , is_list , ListSpec ) ;
291
- into_type ! ( into_hash_table , is_hash_table , HashTableSpec ) ;
292
- into_type ! ( into_hashq_table , is_hash_table , HashQTableSpec ) ;
293
- into_type ! ( into_hashv_table , is_hash_table , HashVTableSpec ) ;
294
- into_type ! ( into_hashx_table , is_hash_table , HashXTableSpec ) ;
295
- } impl Scm < BoolSpec > {
296
- /// Return a true litteral Scm object
297
- # [ inline ] pub fn true_c ( ) -> Scm < BoolSpec > {
298
- Scm :: _from_raw ( unsafe {
299
- gu_SCM_BOOL_T ( )
300
- } )
301
- } /// Return a false litteral Scm object
302
- # [ inline ] pub fn false_c ( ) -> Scm < BoolSpec > {
303
- Scm :: _from_raw ( unsafe {
304
- gu_SCM_BOOL_F ( )
305
- } )
306
- } /// to rust boolean
307
- /// use is_true() for testing trueness
308
- pub fn to_bool ( & self ) -> bool {
309
- unsafe {
310
- scm_to_bool ( self . data ) == 1
311
- }
312
- }
313
- } impl Not for Scm < BoolSpec > {
314
- type Output = Scm < BoolSpec > ;
315
- fn not ( self ) -> Scm < BoolSpec > {
316
- Scm :: _from_raw ( unsafe {
317
- scm_not ( self . data )
318
- } )
319
- }
320
- } guile_impl ! ( impl Scm < StringSpec > {
321
- pub fn from_str < > ( a0 : & str ) -> Scm < StringSpec > {
322
- Scm :: _from_raw ( unsafe {
323
- scm_from_utf8_string ( CString :: new ( a0) . unwrap ( ) . as_ptr ( ) )
324
- } )
325
- } /// to utf8 string
326
- pub fn to_string ( & self ) -> String {
327
- unsafe {
328
- CString :: from_raw ( scm_to_utf8_string ( self . data) ) . into_string ( ) . unwrap ( )
329
- }
330
- } pub fn into_symbol ( self ) -> Scm < SymbolSpec > {
331
- Scm :: _from_raw ( unsafe {
332
- scm_string_to_symbol ( self . data)
333
- } )
334
- }
335
- } ) ;
336
- impl < ' a > From < & ' a str > for Scm < StringSpec > {
337
- # [ inline ] fn from ( s : & ' a str ) -> Scm < StringSpec > {
338
- Scm :: < StringSpec > :: from_str ( s)
339
- }
340
- } impl From < String > for Scm < StringSpec > {
341
- # [ inline ] fn from ( s : String ) -> Scm < StringSpec > {
342
- Scm :: < StringSpec > :: from_str ( & s)
343
- }
344
267
} guile_impl ! ( impl Scm < SymbolSpec > {
345
268
pub fn from_str < > ( a0 : & str ) -> Scm < SymbolSpec > {
346
269
Scm :: _from_raw ( unsafe {
347
270
scm_from_utf8_symbol ( CString :: new ( a0) . unwrap ( ) . as_ptr ( ) )
348
271
} )
349
- } pub fn into_string < > ( self ) -> Scm < StringSpec > {
272
+ } pub fn into_string < > ( self ) -> Scm < self :: String > {
350
273
Scm :: _from_raw ( unsafe {
351
274
scm_symbol_to_string ( self . data)
352
275
} )
@@ -357,23 +280,23 @@ impl < 'a > From < & 'a str > for Scm < SymbolSpec > {
357
280
Scm :: < SymbolSpec > :: from_str ( s)
358
281
}
359
282
} guile_impl ! ( impl Scm < PairSpec > {
360
- pub fn car < > ( & self , ) -> Scm < UnspecifiedSpec > {
283
+ pub fn car < > ( & self , ) -> Scm < Untyped > {
361
284
Scm :: _from_raw ( unsafe {
362
285
gu_scm_car ( self . data)
363
286
} )
364
- } pub fn cdr < > ( & self , ) -> Scm < UnspecifiedSpec > {
287
+ } pub fn cdr < > ( & self , ) -> Scm < Untyped > {
365
288
Scm :: _from_raw ( unsafe {
366
289
gu_scm_cdr ( self . data)
367
290
} )
368
291
} pub fn cons < A : TypeSpec , B : TypeSpec > ( a0 : & Scm < A > , a1 : & Scm < B >) -> Scm < PairSpec > {
369
292
Scm :: _from_raw ( unsafe {
370
293
gu_scm_cons ( a0 . data , a1 . data)
371
294
} )
372
- } pub fn set_car < T : TypeSpec > ( & self , a0 : Scm < T >) -> Scm < UnspecifiedSpec > {
295
+ } pub fn set_car < T : TypeSpec > ( & self , a0 : Scm < T >) -> Scm < Untyped > {
373
296
Scm :: _from_raw ( unsafe {
374
297
scm_set_car_x ( self . data , a0 . data)
375
298
} )
376
- } pub fn set_cdr < T : TypeSpec > ( & self , a0 : Scm < T >) -> Scm < UnspecifiedSpec > {
299
+ } pub fn set_cdr < T : TypeSpec > ( & self , a0 : Scm < T >) -> Scm < Untyped > {
377
300
Scm :: _from_raw ( unsafe {
378
301
scm_set_cdr_x ( self . data , a0 . data)
379
302
} )
@@ -390,23 +313,23 @@ gu_scm_list_n (l . as_mut_ptr ())
390
313
} )
391
314
}
392
315
} guile_impl ! ( impl Scm < ListSpec > {
393
- pub fn length < > ( & self , ) -> Scm < IntSpec > {
316
+ pub fn length < > ( & self , ) -> Scm < Int > {
394
317
Scm :: _from_raw ( unsafe {
395
318
scm_length ( self . data)
396
319
} )
397
320
} pub fn last_pair < > ( & self , ) -> Scm < PairSpec > {
398
321
Scm :: _from_raw ( unsafe {
399
322
scm_last_pair ( self . data)
400
323
} )
401
- } pub fn m_ref < > ( & self , a0 : Scm < IntSpec >) -> Scm < UnspecifiedSpec > {
324
+ } pub fn m_ref < > ( & self , a0 : Scm < Int >) -> Scm < Untyped > {
402
325
Scm :: _from_raw ( unsafe {
403
326
scm_list_ref ( self . data , a0 . data)
404
327
} )
405
- } pub fn tail < > ( & self , a0 : Scm < IntSpec >) -> Scm < ListSpec > {
328
+ } pub fn tail < > ( & self , a0 : Scm < Int >) -> Scm < ListSpec > {
406
329
Scm :: _from_raw ( unsafe {
407
330
scm_list_tail ( self . data , a0 . data)
408
331
} )
409
- } pub fn head < > ( & self , a0 : Scm < IntSpec >) -> Scm < ListSpec > {
332
+ } pub fn head < > ( & self , a0 : Scm < Int >) -> Scm < ListSpec > {
410
333
Scm :: _from_raw ( unsafe {
411
334
scm_list_head ( self . data , a0 . data)
412
335
} )
@@ -425,7 +348,7 @@ scm_make_hash_table (Scm :: from (a0) . data)
425
348
unsafe {
426
349
scm_hash_clear_x ( self . data)
427
350
} ;
428
- } pub fn m_ref < KS : TypeSpec , DS : TypeSpec > ( & self , a0 : Scm < KS > , a1 : Option < Scm < DS > >) -> Scm < UnspecifiedSpec > {
351
+ } pub fn m_ref < KS : TypeSpec , DS : TypeSpec > ( & self , a0 : Scm < KS > , a1 : Option < Scm < DS > >) -> Scm < Untyped > {
429
352
Scm :: _from_raw ( unsafe {
430
353
scm_hash_ref ( self . data , a0 . data , a1 . map_or ( ptr :: null_mut ( ) , | d | d . data) )
431
354
} )
0 commit comments