(index<- ) ./libstd/repr.rs
git branch: * master 5200215 auto merge of #14035 : alexcrichton/rust/experimental, r=huonw
modified: Fri May 9 13:02:28 2014
1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 /*!
12
13 More runtime type reflection
14
15 */
16
17 #![allow(missing_doc)]
18
19 use cast::transmute;
20 use char;
21 use container::Container;
22 use io;
23 use iter::Iterator;
24 use option::{Some, None, Option};
25 use ptr::RawPtr;
26 use reflect;
27 use reflect::{MovePtr, align};
28 use result::{Ok, Err, ResultUnwrap};
29 use str::StrSlice;
30 use to_str::ToStr;
31 use slice::Vector;
32 use intrinsics::{Disr, Opaque, TyDesc, TyVisitor, get_tydesc, visit_tydesc};
33 use raw;
34 use vec::Vec;
35
36 macro_rules! try( ($me:expr, $e:expr) => (
37 match $e {
38 Ok(()) => {},
39 Err(e) => { $me.last_err = Some(e); return false; }
40 }
41 ) )
42
43 /// Representations
44
45 trait Repr {
46 fn write_repr(&self, writer: &mut io::Writer) -> io::IoResult<()>;
47 }
48
49 impl Repr for () {
50 fn write_repr(&self, writer: &mut io::Writer) -> io::IoResult<()> {
51 writer.write("()".as_bytes())
52 }
53 }
54
55 impl Repr for bool {
56 fn write_repr(&self, writer: &mut io::Writer) -> io::IoResult<()> {
57 let s = if *self { "true" } else { "false" };
58 writer.write(s.as_bytes())
59 }
60 }
61
62 impl Repr for int {
63 fn write_repr(&self, writer: &mut io::Writer) -> io::IoResult<()> {
64 write!(writer, "{}", *self)
65 }
66 }
67
68 macro_rules! int_repr(($ty:ident, $suffix:expr) => (impl Repr for $ty {
69 fn write_repr(&self, writer: &mut io::Writer) -> io::IoResult<()> {
70 write!(writer, "{}{}", *self, $suffix)
71 }
72 }))
73
74 int_repr!(i8, "i8")
75 int_repr!(i16, "i16")
76 int_repr!(i32, "i32")
77 int_repr!(i64, "i64")
78 int_repr!(uint, "u")
79 int_repr!(u8, "u8")
80 int_repr!(u16, "u16")
81 int_repr!(u32, "u32")
82 int_repr!(u64, "u64")
83
84 macro_rules! num_repr(($ty:ident, $suffix:expr) => (impl Repr for $ty {
85 fn write_repr(&self, writer: &mut io::Writer) -> io::IoResult<()> {
86 let s = self.to_str();
87 writer.write(s.as_bytes()).and_then(|()| {
88 writer.write(bytes!($suffix))
89 })
90 }
91 }))
92
93 num_repr!(f32, "f32")
94 num_repr!(f64, "f64")
95
96 // New implementation using reflect::MovePtr
97
98 enum VariantState {
99 SearchingFor(Disr),
100 Matched,
101 AlreadyFound
102 }
103
104 pub struct ReprVisitor<'a> {
105 ptr: *u8,
106 ptr_stk: Vec<*u8>,
107 var_stk: Vec<VariantState>,
108 writer: &'a mut io::Writer,
109 last_err: Option<io::IoError>,
110 }
111
112 pub fn ReprVisitor<'a>(ptr: *u8,
113 writer: &'a mut io::Writer) -> ReprVisitor<'a> {
114 ReprVisitor {
115 ptr: ptr,
116 ptr_stk: vec!(),
117 var_stk: vec!(),
118 writer: writer,
119 last_err: None,
120 }
121 }
122
123 impl<'a> MovePtr for ReprVisitor<'a> {
124 #[inline]
125 fn move_ptr(&mut self, adjustment: |*u8| -> *u8) {
126 self.ptr = adjustment(self.ptr);
127 }
128 fn push_ptr(&mut self) {
129 self.ptr_stk.push(self.ptr);
130 }
131 fn pop_ptr(&mut self) {
132 self.ptr = self.ptr_stk.pop().unwrap();
133 }
134 }
135
136 impl<'a> ReprVisitor<'a> {
137 // Various helpers for the TyVisitor impl
138
139 #[inline]
140 pub fn get<T>(&mut self, f: |&mut ReprVisitor, &T| -> bool) -> bool {
141 unsafe {
142 f(self, transmute::<*u8,&T>(self.ptr))
143 }
144 }
145
146 #[inline]
147 pub fn visit_inner(&mut self, inner: *TyDesc) -> bool {
148 self.visit_ptr_inner(self.ptr, inner)
149 }
150
151 #[inline]
152 pub fn visit_ptr_inner(&mut self, ptr: *u8, inner: *TyDesc) -> bool {
153 unsafe {
154 // This should call the constructor up above, but due to limiting
155 // issues we have to recreate it here.
156 let u = ReprVisitor {
157 ptr: ptr,
158 ptr_stk: vec!(),
159 var_stk: vec!(),
160 writer: ::cast::transmute_copy(&self.writer),
161 last_err: None,
162 };
163 let mut v = reflect::MovePtrAdaptor(u);
164 // Obviously this should not be a thing, but blame #8401 for now
165 visit_tydesc(inner, &mut v as &mut TyVisitor);
166 match v.unwrap().last_err {
167 Some(e) => {
168 self.last_err = Some(e);
169 false
170 }
171 None => true,
172 }
173 }
174 }
175
176 #[inline]
177 pub fn write<T:Repr>(&mut self) -> bool {
178 self.get(|this, v:&T| {
179 try!(this, v.write_repr(this.writer));
180 true
181 })
182 }
183
184 pub fn write_escaped_slice(&mut self, slice: &str) -> bool {
185 try!(self, self.writer.write(['"' as u8]));
186 for ch in slice.chars() {
187 if !self.write_escaped_char(ch, true) { return false }
188 }
189 try!(self, self.writer.write(['"' as u8]));
190 true
191 }
192
193 pub fn write_mut_qualifier(&mut self, mtbl: uint) -> bool {
194 if mtbl == 0 {
195 try!(self, self.writer.write("mut ".as_bytes()));
196 } else if mtbl == 1 {
197 // skip, this is ast::m_imm
198 } else {
199 fail!("invalid mutability value");
200 }
201 true
202 }
203
204 pub fn write_vec_range(&mut self, ptr: *(), len: uint, inner: *TyDesc) -> bool {
205 let mut p = ptr as *u8;
206 let (sz, al) = unsafe { ((*inner).size, (*inner).align) };
207 try!(self, self.writer.write(['[' as u8]));
208 let mut first = true;
209 let mut left = len;
210 // unit structs have 0 size, and don't loop forever.
211 let dec = if sz == 0 {1} else {sz};
212 while left > 0 {
213 if first {
214 first = false;
215 } else {
216 try!(self, self.writer.write(", ".as_bytes()));
217 }
218 self.visit_ptr_inner(p as *u8, inner);
219 p = align(unsafe { p.offset(sz as int) as uint }, al) as *u8;
220 left -= dec;
221 }
222 try!(self, self.writer.write([']' as u8]));
223 true
224 }
225
226 pub fn write_unboxed_vec_repr(&mut self, _: uint, v: &raw::Vec<()>, inner: *TyDesc) -> bool {
227 self.write_vec_range(&v.data, v.fill, inner)
228 }
229
230 fn write_escaped_char(&mut self, ch: char, is_str: bool) -> bool {
231 try!(self, match ch {
232 '\t' => self.writer.write("\\t".as_bytes()),
233 '\r' => self.writer.write("\\r".as_bytes()),
234 '\n' => self.writer.write("\\n".as_bytes()),
235 '\\' => self.writer.write("\\\\".as_bytes()),
236 '\'' => {
237 if is_str {
238 self.writer.write("'".as_bytes())
239 } else {
240 self.writer.write("\\'".as_bytes())
241 }
242 }
243 '"' => {
244 if is_str {
245 self.writer.write("\\\"".as_bytes())
246 } else {
247 self.writer.write("\"".as_bytes())
248 }
249 }
250 '\x20'..'\x7e' => self.writer.write([ch as u8]),
251 _ => {
252 char::escape_unicode(ch, |c| {
253 let _ = self.writer.write([c as u8]);
254 });
255 Ok(())
256 }
257 });
258 return true;
259 }
260 }
261
262 impl<'a> TyVisitor for ReprVisitor<'a> {
263 fn visit_bot(&mut self) -> bool {
264 try!(self, self.writer.write("!".as_bytes()));
265 true
266 }
267 fn visit_nil(&mut self) -> bool { self.write::<()>() }
268 fn visit_bool(&mut self) -> bool { self.write::<bool>() }
269 fn visit_int(&mut self) -> bool { self.write::<int>() }
270 fn visit_i8(&mut self) -> bool { self.write::<i8>() }
271 fn visit_i16(&mut self) -> bool { self.write::<i16>() }
272 fn visit_i32(&mut self) -> bool { self.write::<i32>() }
273 fn visit_i64(&mut self) -> bool { self.write::<i64>() }
274
275 fn visit_uint(&mut self) -> bool { self.write::<uint>() }
276 fn visit_u8(&mut self) -> bool { self.write::<u8>() }
277 fn visit_u16(&mut self) -> bool { self.write::<u16>() }
278 fn visit_u32(&mut self) -> bool { self.write::<u32>() }
279 fn visit_u64(&mut self) -> bool { self.write::<u64>() }
280
281 fn visit_f32(&mut self) -> bool { self.write::<f32>() }
282 fn visit_f64(&mut self) -> bool { self.write::<f64>() }
283 fn visit_f128(&mut self) -> bool { fail!("not implemented") }
284
285 fn visit_char(&mut self) -> bool {
286 self.get::<char>(|this, &ch| {
287 try!(this, this.writer.write(['\'' as u8]));
288 if !this.write_escaped_char(ch, false) { return false }
289 try!(this, this.writer.write(['\'' as u8]));
290 true
291 })
292 }
293
294 fn visit_estr_box(&mut self) -> bool {
295 true
296 }
297
298 fn visit_estr_uniq(&mut self) -> bool {
299 self.get::<~str>(|this, s| {
300 try!(this, this.writer.write(['~' as u8]));
301 this.write_escaped_slice(*s)
302 })
303 }
304
305 fn visit_estr_slice(&mut self) -> bool {
306 self.get::<&str>(|this, s| this.write_escaped_slice(*s))
307 }
308
309 // Type no longer exists, vestigial function.
310 fn visit_estr_fixed(&mut self, _n: uint, _sz: uint,
311 _align: uint) -> bool { fail!(); }
312
313 fn visit_box(&mut self, mtbl: uint, inner: *TyDesc) -> bool {
314 try!(self, self.writer.write(['@' as u8]));
315 self.write_mut_qualifier(mtbl);
316 self.get::<&raw::Box<()>>(|this, b| {
317 let p = &b.data as *() as *u8;
318 this.visit_ptr_inner(p, inner)
319 })
320 }
321
322 fn visit_uniq(&mut self, _mtbl: uint, inner: *TyDesc) -> bool {
323 try!(self, self.writer.write("box ".as_bytes()));
324 self.get::<*u8>(|this, b| {
325 this.visit_ptr_inner(*b, inner)
326 })
327 }
328
329 fn visit_ptr(&mut self, mtbl: uint, _inner: *TyDesc) -> bool {
330 self.get::<*u8>(|this, p| {
331 try!(this, write!(this.writer, "({} as *", *p));
332 this.write_mut_qualifier(mtbl);
333 try!(this, this.writer.write("())".as_bytes()));
334 true
335 })
336 }
337
338 fn visit_rptr(&mut self, mtbl: uint, inner: *TyDesc) -> bool {
339 try!(self, self.writer.write(['&' as u8]));
340 self.write_mut_qualifier(mtbl);
341 self.get::<*u8>(|this, p| {
342 this.visit_ptr_inner(*p, inner)
343 })
344 }
345
346 fn visit_evec_box(&mut self, mtbl: uint, inner: *TyDesc) -> bool {
347 self.get::<&raw::Box<raw::Vec<()>>>(|this, b| {
348 try!(this, this.writer.write(['@' as u8]));
349 this.write_mut_qualifier(mtbl);
350 this.write_unboxed_vec_repr(mtbl, &b.data, inner)
351 })
352 }
353
354 fn visit_evec_uniq(&mut self, mtbl: uint, inner: *TyDesc) -> bool {
355 self.get::<&raw::Vec<()>>(|this, b| {
356 try!(this, this.writer.write("box ".as_bytes()));
357 this.write_unboxed_vec_repr(mtbl, *b, inner)
358 })
359 }
360
361 fn visit_evec_slice(&mut self, mtbl: uint, inner: *TyDesc) -> bool {
362 self.get::<raw::Slice<()>>(|this, s| {
363 try!(this, this.writer.write(['&' as u8]));
364 this.write_mut_qualifier(mtbl);
365 let size = unsafe {
366 if (*inner).size == 0 { 1 } else { (*inner).size }
367 };
368 this.write_vec_range(s.data, s.len * size, inner)
369 })
370 }
371
372 fn visit_evec_fixed(&mut self, n: uint, sz: uint, _align: uint,
373 _: uint, inner: *TyDesc) -> bool {
374 let assumed_size = if sz == 0 { n } else { sz };
375 self.get::<()>(|this, b| {
376 this.write_vec_range(b, assumed_size, inner)
377 })
378 }
379
380 fn visit_enter_rec(&mut self, _n_fields: uint,
381 _sz: uint, _align: uint) -> bool {
382 try!(self, self.writer.write(['{' as u8]));
383 true
384 }
385
386 fn visit_rec_field(&mut self, i: uint, name: &str,
387 mtbl: uint, inner: *TyDesc) -> bool {
388 if i != 0 {
389 try!(self, self.writer.write(", ".as_bytes()));
390 }
391 self.write_mut_qualifier(mtbl);
392 try!(self, self.writer.write(name.as_bytes()));
393 try!(self, self.writer.write(": ".as_bytes()));
394 self.visit_inner(inner);
395 true
396 }
397
398 fn visit_leave_rec(&mut self, _n_fields: uint,
399 _sz: uint, _align: uint) -> bool {
400 try!(self, self.writer.write(['}' as u8]));
401 true
402 }
403
404 fn visit_enter_class(&mut self, name: &str, named_fields: bool, n_fields: uint,
405 _sz: uint, _align: uint) -> bool {
406 try!(self, self.writer.write(name.as_bytes()));
407 if n_fields != 0 {
408 if named_fields {
409 try!(self, self.writer.write(['{' as u8]));
410 } else {
411 try!(self, self.writer.write(['(' as u8]));
412 }
413 }
414 true
415 }
416
417 fn visit_class_field(&mut self, i: uint, name: &str, named: bool,
418 _mtbl: uint, inner: *TyDesc) -> bool {
419 if i != 0 {
420 try!(self, self.writer.write(", ".as_bytes()));
421 }
422 if named {
423 try!(self, self.writer.write(name.as_bytes()));
424 try!(self, self.writer.write(": ".as_bytes()));
425 }
426 self.visit_inner(inner);
427 true
428 }
429
430 fn visit_leave_class(&mut self, _name: &str, named_fields: bool, n_fields: uint,
431 _sz: uint, _align: uint) -> bool {
432 if n_fields != 0 {
433 if named_fields {
434 try!(self, self.writer.write(['}' as u8]));
435 } else {
436 try!(self, self.writer.write([')' as u8]));
437 }
438 }
439 true
440 }
441
442 fn visit_enter_tup(&mut self, _n_fields: uint,
443 _sz: uint, _align: uint) -> bool {
444 try!(self, self.writer.write(['(' as u8]));
445 true
446 }
447
448 fn visit_tup_field(&mut self, i: uint, inner: *TyDesc) -> bool {
449 if i != 0 {
450 try!(self, self.writer.write(", ".as_bytes()));
451 }
452 self.visit_inner(inner);
453 true
454 }
455
456 fn visit_leave_tup(&mut self, _n_fields: uint,
457 _sz: uint, _align: uint) -> bool {
458 if _n_fields == 1 {
459 try!(self, self.writer.write([',' as u8]));
460 }
461 try!(self, self.writer.write([')' as u8]));
462 true
463 }
464
465 fn visit_enter_enum(&mut self,
466 _n_variants: uint,
467 get_disr: extern unsafe fn(ptr: *Opaque) -> Disr,
468 _sz: uint,
469 _align: uint) -> bool {
470 let disr = unsafe {
471 get_disr(transmute(self.ptr))
472 };
473 self.var_stk.push(SearchingFor(disr));
474 true
475 }
476
477 fn visit_enter_enum_variant(&mut self, _variant: uint,
478 disr_val: Disr,
479 n_fields: uint,
480 name: &str) -> bool {
481 let mut write = false;
482 match self.var_stk.pop().unwrap() {
483 SearchingFor(sought) => {
484 if disr_val == sought {
485 self.var_stk.push(Matched);
486 write = true;
487 } else {
488 self.var_stk.push(SearchingFor(sought));
489 }
490 }
491 Matched | AlreadyFound => {
492 self.var_stk.push(AlreadyFound);
493 }
494 }
495
496 if write {
497 try!(self, self.writer.write(name.as_bytes()));
498 if n_fields > 0 {
499 try!(self, self.writer.write(['(' as u8]));
500 }
501 }
502 true
503 }
504
505 fn visit_enum_variant_field(&mut self,
506 i: uint,
507 _offset: uint,
508 inner: *TyDesc)
509 -> bool {
510 match *self.var_stk.get(self.var_stk.len() - 1) {
511 Matched => {
512 if i != 0 {
513 try!(self, self.writer.write(", ".as_bytes()));
514 }
515 if ! self.visit_inner(inner) {
516 return false;
517 }
518 }
519 _ => ()
520 }
521 true
522 }
523
524 fn visit_leave_enum_variant(&mut self, _variant: uint,
525 _disr_val: Disr,
526 n_fields: uint,
527 _name: &str) -> bool {
528 match *self.var_stk.get(self.var_stk.len() - 1) {
529 Matched => {
530 if n_fields > 0 {
531 try!(self, self.writer.write([')' as u8]));
532 }
533 }
534 _ => ()
535 }
536 true
537 }
538
539 fn visit_leave_enum(&mut self,
540 _n_variants: uint,
541 _get_disr: extern unsafe fn(ptr: *Opaque) -> Disr,
542 _sz: uint,
543 _align: uint)
544 -> bool {
545 match self.var_stk.pop().unwrap() {
546 SearchingFor(..) => fail!("enum value matched no variant"),
547 _ => true
548 }
549 }
550
551 fn visit_enter_fn(&mut self, _purity: uint, _proto: uint,
552 _n_inputs: uint, _retstyle: uint) -> bool {
553 try!(self, self.writer.write("fn(".as_bytes()));
554 true
555 }
556
557 fn visit_fn_input(&mut self, i: uint, _mode: uint, inner: *TyDesc) -> bool {
558 if i != 0 {
559 try!(self, self.writer.write(", ".as_bytes()));
560 }
561 let name = unsafe { (*inner).name };
562 try!(self, self.writer.write(name.as_bytes()));
563 true
564 }
565
566 fn visit_fn_output(&mut self, _retstyle: uint, variadic: bool,
567 inner: *TyDesc) -> bool {
568 if variadic {
569 try!(self, self.writer.write(", ...".as_bytes()));
570 }
571 try!(self, self.writer.write(")".as_bytes()));
572 let name = unsafe { (*inner).name };
573 if name != "()" {
574 try!(self, self.writer.write(" -> ".as_bytes()));
575 try!(self, self.writer.write(name.as_bytes()));
576 }
577 true
578 }
579
580 fn visit_leave_fn(&mut self, _purity: uint, _proto: uint,
581 _n_inputs: uint, _retstyle: uint) -> bool { true }
582
583
584 fn visit_trait(&mut self, name: &str) -> bool {
585 try!(self, self.writer.write(name.as_bytes()));
586 true
587 }
588
589 fn visit_param(&mut self, _i: uint) -> bool { true }
590 fn visit_self(&mut self) -> bool { true }
591 }
592
593 pub fn write_repr<T>(writer: &mut io::Writer, object: &T) -> io::IoResult<()> {
594 unsafe {
595 let ptr = object as *T as *u8;
596 let tydesc = get_tydesc::<T>();
597 let u = ReprVisitor(ptr, writer);
598 let mut v = reflect::MovePtrAdaptor(u);
599 visit_tydesc(tydesc, &mut v as &mut TyVisitor);
600 match v.unwrap().last_err {
601 Some(e) => Err(e),
602 None => Ok(()),
603 }
604 }
605 }
606
607 pub fn repr_to_str<T>(t: &T) -> ~str {
608 use str;
609 use str::StrAllocating;
610 use io;
611
612 let mut result = io::MemWriter::new();
613 write_repr(&mut result as &mut io::Writer, t).unwrap();
614 str::from_utf8(result.unwrap().as_slice()).unwrap().to_owned()
615 }
616
617 #[cfg(test)]
618 struct P {a: int, b: f64}
619
620 #[test]
621 fn test_repr() {
622 use prelude::*;
623 use str;
624 use str::Str;
625 use io::stdio::println;
626 use char::is_alphabetic;
627 use mem::swap;
628
629 fn exact_test<T>(t: &T, e:&str) {
630 let mut m = io::MemWriter::new();
631 write_repr(&mut m as &mut io::Writer, t).unwrap();
632 let s = str::from_utf8(m.unwrap().as_slice()).unwrap().to_owned();
633 assert_eq!(s.as_slice(), e);
634 }
635
636 exact_test(&10, "10");
637 exact_test(&true, "true");
638 exact_test(&false, "false");
639 exact_test(&1.234, "1.234f64");
640 exact_test(&("hello"), "\"hello\"");
641 // FIXME What do I do about this one?
642 exact_test(&("he\u10f3llo".to_owned()), "~\"he\\u10f3llo\"");
643
644 exact_test(&(@10), "@10");
645 exact_test(&(box 10), "box 10");
646 exact_test(&(&10), "&10");
647 let mut x = 10;
648 exact_test(&(&mut x), "&mut 10");
649
650 exact_test(&(0 as *()), "(0x0 as *())");
651 exact_test(&(0 as *mut ()), "(0x0 as *mut ())");
652
653 exact_test(&(1,), "(1,)");
654 exact_test(&(&["hi", "there"]),
655 "&[\"hi\", \"there\"]");
656 exact_test(&(P{a:10, b:1.234}),
657 "repr::P{a: 10, b: 1.234f64}");
658 exact_test(&(@P{a:10, b:1.234}),
659 "@repr::P{a: 10, b: 1.234f64}");
660 exact_test(&(box P{a:10, b:1.234}),
661 "box repr::P{a: 10, b: 1.234f64}");
662 exact_test(&(10u8, "hello".to_owned()),
663 "(10u8, ~\"hello\")");
664 exact_test(&(10u16, "hello".to_owned()),
665 "(10u16, ~\"hello\")");
666 exact_test(&(10u32, "hello".to_owned()),
667 "(10u32, ~\"hello\")");
668 exact_test(&(10u64, "hello".to_owned()),
669 "(10u64, ~\"hello\")");
670
671 exact_test(&(&[1, 2]), "&[1, 2]");
672 exact_test(&(&mut [1, 2]), "&mut [1, 2]");
673
674 exact_test(&'\'', "'\\''");
675 exact_test(&'"', "'\"'");
676 exact_test(&("'"), "\"'\"");
677 exact_test(&("\""), "\"\\\"\"");
678
679 exact_test(&println, "fn(&str)");
680 exact_test(&swap::<int>, "fn(&mut int, &mut int)");
681 exact_test(&is_alphabetic, "fn(char) -> bool");
682
683 struct Bar(int, int);
684 exact_test(&(Bar(2, 2)), "repr::test_repr::Bar(2, 2)");
685 }
libstd/repr.rs:44:1-44:1 -trait- definition:
trait Repr {
fn write_repr(&self, writer: &mut io::Writer) -> io::IoResult<()>;
}
references:- 1568: macro_rules! int_repr(($ty:ident, $suffix:expr) => (impl Repr for $ty {
69: fn write_repr(&self, writer: &mut io::Writer) -> io::IoResult<()> {
--
176: #[inline]
177: pub fn write<T:Repr>(&mut self) -> bool {
178: self.get(|this, v:&T| {
libstd/repr.rs:103:1-103:1 -struct- definition:
pub struct ReprVisitor<'a> {
ptr: *u8,
ptr_stk: Vec<*u8>,
references:- 7155: // issues we have to recreate it here.
156: let u = ReprVisitor {
157: ptr: ptr,
--
262: impl<'a> TyVisitor for ReprVisitor<'a> {
263: fn visit_bot(&mut self) -> bool {
libstd/repr.rs:592:1-592:1 -fn- definition:
pub fn write_repr<T>(writer: &mut io::Writer, object: &T) -> io::IoResult<()> {
unsafe {
let ptr = object as *T as *u8;
references:- 2libstd/fmt/mod.rs:
1215: (None, None) => {
1216: repr::write_repr(f.buf, self)
1217: }
libstd/repr.rs:
612: let mut result = io::MemWriter::new();
613: write_repr(&mut result as &mut io::Writer, t).unwrap();
614: str::from_utf8(result.unwrap().as_slice()).unwrap().to_owned()