mirror of
https://github.com/rust-lang/rust.git
synced 2026-03-20 00:15:17 +00:00
Page:
Doc lowlevel details
Pages
Anticipated breaking changes during 1.0 alpha
Community User Groups, Meetups, and Events
Community libraries
Doc continuous integration
Doc how to install an unofficial nightly for Windows
Doc Emacs Support
Doc FAQ Cheatsheet
Doc building for android
Doc building for ios
Doc detailed release notes
Doc examples
Doc friends of the tree
Doc language faq
Doc lowlevel details
Doc packages, editors, and other tools
Doc releases
Doc under construction FAQ
Doc vim support
Docs project structure
Docs
Games written in Rust
Home
Howto submit a rust bug report
IRC notifications channel
Lib datetime
Lib fmt
Lib html
Lib io
Lib rand
Lib re
Library editing
Libs
Meeting API review 2014 06 23
Meeting RFC triage 2014 06 19
Mixed language link time optimization
Note Building Rust Before 0.8 on Windows Systems
Note 0.5 priorities
Note Intrinsics
Note Rust performance fixes
Note bors usage
Note buildbots
Note code review
Note compiler snapshots
Note core team
Note development policy
Note getting started developing Rust
Note git workflow
Note guide for new contributors
Note operator overloading
Note priority issue criteria
Note research
Note rustc hacking guide back end
Note rustc hacking guide front end
Note rustc hacking guide middle end
Note rustc hacking guide
Note seeing LLVM output from rust
Note style guide
Note tag label names and definitions
Note testsuite
Note wiki conventions
Notes
OS Bridge 2013 tutorial
Operating system development
Projects using Rust
Rustpkg schedule
Sigil reference
Teaching Rust
The Rusticon
Using Rust on Windows
lib template
No results
5
Doc lowlevel details
Corey Richardson edited this page 2013-06-22 06:06:33 -07:00
Table of Contents
Method Dispatch
Type-parameterized functions are specialized for each set of type parameters used to instantiate them in a crate. The method calls are resolved statically at compile-time. Example:
fn foo<T: ToStr>(x: &T) -> ~str { x.to_str() }
foo(&5u); // `foo<uint>` is instantiated for this crate
Using traits as objects is dynamic dispatch at runtime. The method calls are resolved by dereferencing a pointer to a vtable at runtime and then calling a function pointer. Example:
fn foo(x: &ToStr) -> ~str { x.to_str() }
foo(&5u as &ToStr); // a vtable is generated for `uint` with the `to_str` method
At runtime, &ToStr is represented as a a pointer to a vtable with all the methods in the trait (just to_str in this case) and a pointer to the value. The pointer to the value is the pointer sigil in front of the trait object.
All Categories:
- Docs -- For users
- Notes -- For developers
- Libs -- For library authors
- Meeting minutes