Skip to main content

Vehicle

Struct Vehicle 

Source
pub struct Vehicle {
Show 25 fields pub top_speed: f32, pub reverse_speed: f32, pub engine_force: f32, pub brake_force: f32, pub grip: f32, pub rolling_resistance: f32, pub engine_braking: f32, pub turn_radius: f32, pub max_turn_rate: f32, pub gears: u32, pub idle_rpm: f32, pub max_rpm: f32, pub load: f32, pub max_load: f32, pub fuel_capacity: Option<f32>, pub consumption: f32, pub engine_sound: Option<String>, pub horn_sound: Option<String>, pub start_sound: Option<String>, pub shift_sound: Option<String>, pub crash_sound: Option<String>, pub throttle: f32, pub brake: f32, pub steer: f32, pub handbrake: bool, /* private fields */
}
Expand description

The vehicle part of a body: settings, pedals and the driving state.

Settings are public fields with with_* builder methods. Speeds are stored in meters per second; the builders that take km/h say so in their name.

Fields§

§top_speed: f32

Highest forward speed in m/s. The engine gets weaker towards it, so full throttle approaches it slowly.

§reverse_speed: f32

Highest reverse speed in m/s.

§engine_force: f32

Driving force of the engine at full throttle in newtons. Acceleration is this divided by the weight.

§brake_force: f32

Braking force at full brake pedal in newtons. Deceleration is this divided by the weight.

§grip: f32

Most acceleration or deceleration the tyres can transfer, in m/s². Caps engine, brakes and handbrake. 9 is a car on dry asphalt, 3 is a wet road, 1 is ice.

§rolling_resistance: f32

Speed lost per second while rolling, in m/s² (tyres, air). Always active.

§engine_braking: f32

Extra speed lost per second when no pedal is pressed and the engine runs, in m/s².

§turn_radius: f32

Radius of the tightest circle the vehicle can drive, in meters.

§max_turn_rate: f32

Fastest the vehicle can turn, in degrees per second.

§gears: u32

Number of forward gears (at least 1).

§idle_rpm: f32

Engine speed when idling, in revolutions per minute.

§max_rpm: f32

Highest engine speed, in revolutions per minute.

§load: f32

Cargo in kilograms, added to the body’s mass. Change it with Vehicle::set_load to respect Vehicle::max_load.

§max_load: f32

Most cargo in kilograms. Default unlimited.

§fuel_capacity: Option<f32>

Tank size in liters, None (the default) for unlimited fuel.

§consumption: f32

Fuel use in liters per 100 km at full throttle with an empty vehicle. Light throttle uses less, cargo uses more.

§engine_sound: Option<String>

Looping engine sound, played at the vehicle while the engine runs. Its pitch follows the engine speed and its volume the throttle.

§horn_sound: Option<String>

Sound for Context::horn.

§start_sound: Option<String>§shift_sound: Option<String>

Sound played on every gear change.

§crash_sound: Option<String>

Sound played when the vehicle crashes into something, louder for harder crashes.

§throttle: f32

Gas pedal, 0.0 to 1.0. Set it every frame. While reversing it brakes.

§brake: f32

Brake pedal, 0.0 to 1.0. Set it every frame. Pressed while the vehicle stands still, it drives backwards (after braking to a stop, release it and press it again).

§steer: f32

Steering wheel, -1.0 (full left) to 1.0 (full right).

§handbrake: bool

Handbrake: stops the vehicle as hard as the grip allows.

Implementations§

Source§

impl Vehicle

Source

pub fn car() -> Self

A car: top speed 180 km/h, 0 to 100 km/h in about 10 seconds with Body::car’s 1300 kg, 5 gears, turns in a 5 m circle.

Examples found in repository?
examples/driving.rs (line 49)
29    fn new(ctx: &mut Context) -> Self {
30        // Engine: a low buzz that loops without clicks (whole cycles, no fades).
31        let engine = Synth::saw(55.0).length(1.0).attack(0.0).release(0.0).volume(0.25)
32            .with(Synth::square(110.0).length(1.0).attack(0.0).release(0.0).volume(0.08));
33        ctx.audio.register("engine", engine);
34        ctx.audio.register("horn", Synth::square(415.0).length(0.5).volume(0.25).with(Synth::square(523.0).length(0.5).volume(0.2)));
35        ctx.audio.register("shift", Synth::noise().length(0.04).decay(90.0).volume(0.3));
36        ctx.audio.register("crash", Synth::noise().length(0.4).decay(10.0).volume(0.8).with(Synth::sine(80.0).sweep_to(30.0).length(0.3)));
37        ctx.audio.register("start", Synth::saw(40.0).sweep_to(55.0).length(0.6).volume(0.3));
38        ctx.audio.register("garage", Synth::sine(880.0).length(0.15).decay(10.0));
39
40        let level = ctx.physics.build_level(MAP, 6.0);
41        let sounds = |v: Vehicle| {
42            v.with_engine_sound("engine")
43                .with_horn_sound("horn")
44                .with_shift_sound("shift")
45                .with_crash_sound("crash")
46                .with_start_sound("start")
47        };
48        let car_start = level.point('P').unwrap_or(Vec3::ZERO);
49        let car = ctx.physics.add(Body::car(car_start).with_facing(90.0).with_vehicle(sounds(Vehicle::car().with_fuel(5.0, 8.0))));
50        let truck_start = level.point('T').unwrap_or(Vec3::ZERO);
51        let truck = ctx.physics.add(
52            Body::truck(truck_start).with_facing(90.0).with_vehicle(sounds(Vehicle::truck()).engine_off()),
53        );
54        let garage_at = level.point('G').unwrap_or(Vec3::ZERO);
55        let garage = ctx.physics.add(Body::sensor(garage_at).with_box(6.0, 6.0, 3.0).with_tag("garage"));
56        ctx.loop_on(garage, "garage");
57        ctx.follow(car);
58        Self { car, truck, driving: car, garage }
59    }
Source

pub fn truck() -> Self

A truck: top speed 90 km/h, 12 gears, turns in an 11 m circle, carries up to 25 t. With Body::truck’s 12 t it reaches 60 km/h in about 13 seconds empty and in about 50 seconds fully loaded.

Examples found in repository?
examples/driving.rs (line 52)
29    fn new(ctx: &mut Context) -> Self {
30        // Engine: a low buzz that loops without clicks (whole cycles, no fades).
31        let engine = Synth::saw(55.0).length(1.0).attack(0.0).release(0.0).volume(0.25)
32            .with(Synth::square(110.0).length(1.0).attack(0.0).release(0.0).volume(0.08));
33        ctx.audio.register("engine", engine);
34        ctx.audio.register("horn", Synth::square(415.0).length(0.5).volume(0.25).with(Synth::square(523.0).length(0.5).volume(0.2)));
35        ctx.audio.register("shift", Synth::noise().length(0.04).decay(90.0).volume(0.3));
36        ctx.audio.register("crash", Synth::noise().length(0.4).decay(10.0).volume(0.8).with(Synth::sine(80.0).sweep_to(30.0).length(0.3)));
37        ctx.audio.register("start", Synth::saw(40.0).sweep_to(55.0).length(0.6).volume(0.3));
38        ctx.audio.register("garage", Synth::sine(880.0).length(0.15).decay(10.0));
39
40        let level = ctx.physics.build_level(MAP, 6.0);
41        let sounds = |v: Vehicle| {
42            v.with_engine_sound("engine")
43                .with_horn_sound("horn")
44                .with_shift_sound("shift")
45                .with_crash_sound("crash")
46                .with_start_sound("start")
47        };
48        let car_start = level.point('P').unwrap_or(Vec3::ZERO);
49        let car = ctx.physics.add(Body::car(car_start).with_facing(90.0).with_vehicle(sounds(Vehicle::car().with_fuel(5.0, 8.0))));
50        let truck_start = level.point('T').unwrap_or(Vec3::ZERO);
51        let truck = ctx.physics.add(
52            Body::truck(truck_start).with_facing(90.0).with_vehicle(sounds(Vehicle::truck()).engine_off()),
53        );
54        let garage_at = level.point('G').unwrap_or(Vec3::ZERO);
55        let garage = ctx.physics.add(Body::sensor(garage_at).with_box(6.0, 6.0, 3.0).with_tag("garage"));
56        ctx.loop_on(garage, "garage");
57        ctx.follow(car);
58        Self { car, truck, driving: car, garage }
59    }
Source

pub fn with_top_speed_kmh(self, kmh: f32) -> Self

Sets the top speed in km/h.

Source

pub fn with_reverse_speed_kmh(self, kmh: f32) -> Self

Sets the top reverse speed in km/h.

Source

pub fn with_engine_force(self, newtons: f32) -> Self

Sets the engine force in newtons (car 4500, truck 20000). More force, faster acceleration.

Source

pub fn with_brake_force(self, newtons: f32) -> Self

Sets the brake force in newtons (car 11000, truck 110000).

Source

pub fn with_grip(self, grip: f32) -> Self

Sets the tyre grip in m/s² (9 dry, 3 wet, 1 ice).

Source

pub fn with_rolling_resistance(self, resistance: f32) -> Self

Sets the rolling resistance in m/s².

Source

pub fn with_engine_braking(self, braking: f32) -> Self

Sets the engine braking in m/s² (how fast the vehicle slows down off the gas).

Source

pub fn with_turn_radius(self, meters: f32) -> Self

Sets the radius of the tightest circle in meters.

Source

pub fn with_max_turn_rate(self, degrees_per_second: f32) -> Self

Sets the fastest turn rate in degrees per second.

Source

pub fn with_gears(self, gears: u32, idle_rpm: f32, max_rpm: f32) -> Self

Sets the gearbox: number of forward gears, idle and highest engine speed in rpm.

Source

pub fn with_load(self, kg: f32) -> Self

Sets the cargo in kilograms (limited by Vehicle::max_load).

Source

pub fn with_max_load(self, kg: f32) -> Self

Sets the most cargo in kilograms.

Source

pub fn with_fuel(self, capacity: f32, liters_per_100km: f32) -> Self

Gives the vehicle a tank of capacity liters, starting full, that uses liters_per_100km at full throttle. Without this, fuel is unlimited.

Examples found in repository?
examples/driving.rs (line 49)
29    fn new(ctx: &mut Context) -> Self {
30        // Engine: a low buzz that loops without clicks (whole cycles, no fades).
31        let engine = Synth::saw(55.0).length(1.0).attack(0.0).release(0.0).volume(0.25)
32            .with(Synth::square(110.0).length(1.0).attack(0.0).release(0.0).volume(0.08));
33        ctx.audio.register("engine", engine);
34        ctx.audio.register("horn", Synth::square(415.0).length(0.5).volume(0.25).with(Synth::square(523.0).length(0.5).volume(0.2)));
35        ctx.audio.register("shift", Synth::noise().length(0.04).decay(90.0).volume(0.3));
36        ctx.audio.register("crash", Synth::noise().length(0.4).decay(10.0).volume(0.8).with(Synth::sine(80.0).sweep_to(30.0).length(0.3)));
37        ctx.audio.register("start", Synth::saw(40.0).sweep_to(55.0).length(0.6).volume(0.3));
38        ctx.audio.register("garage", Synth::sine(880.0).length(0.15).decay(10.0));
39
40        let level = ctx.physics.build_level(MAP, 6.0);
41        let sounds = |v: Vehicle| {
42            v.with_engine_sound("engine")
43                .with_horn_sound("horn")
44                .with_shift_sound("shift")
45                .with_crash_sound("crash")
46                .with_start_sound("start")
47        };
48        let car_start = level.point('P').unwrap_or(Vec3::ZERO);
49        let car = ctx.physics.add(Body::car(car_start).with_facing(90.0).with_vehicle(sounds(Vehicle::car().with_fuel(5.0, 8.0))));
50        let truck_start = level.point('T').unwrap_or(Vec3::ZERO);
51        let truck = ctx.physics.add(
52            Body::truck(truck_start).with_facing(90.0).with_vehicle(sounds(Vehicle::truck()).engine_off()),
53        );
54        let garage_at = level.point('G').unwrap_or(Vec3::ZERO);
55        let garage = ctx.physics.add(Body::sensor(garage_at).with_box(6.0, 6.0, 3.0).with_tag("garage"));
56        ctx.loop_on(garage, "garage");
57        ctx.follow(car);
58        Self { car, truck, driving: car, garage }
59    }
Source

pub fn with_engine_sound(self, name: impl Into<String>) -> Self

Sets the looping engine sound.

Examples found in repository?
examples/driving.rs (line 42)
29    fn new(ctx: &mut Context) -> Self {
30        // Engine: a low buzz that loops without clicks (whole cycles, no fades).
31        let engine = Synth::saw(55.0).length(1.0).attack(0.0).release(0.0).volume(0.25)
32            .with(Synth::square(110.0).length(1.0).attack(0.0).release(0.0).volume(0.08));
33        ctx.audio.register("engine", engine);
34        ctx.audio.register("horn", Synth::square(415.0).length(0.5).volume(0.25).with(Synth::square(523.0).length(0.5).volume(0.2)));
35        ctx.audio.register("shift", Synth::noise().length(0.04).decay(90.0).volume(0.3));
36        ctx.audio.register("crash", Synth::noise().length(0.4).decay(10.0).volume(0.8).with(Synth::sine(80.0).sweep_to(30.0).length(0.3)));
37        ctx.audio.register("start", Synth::saw(40.0).sweep_to(55.0).length(0.6).volume(0.3));
38        ctx.audio.register("garage", Synth::sine(880.0).length(0.15).decay(10.0));
39
40        let level = ctx.physics.build_level(MAP, 6.0);
41        let sounds = |v: Vehicle| {
42            v.with_engine_sound("engine")
43                .with_horn_sound("horn")
44                .with_shift_sound("shift")
45                .with_crash_sound("crash")
46                .with_start_sound("start")
47        };
48        let car_start = level.point('P').unwrap_or(Vec3::ZERO);
49        let car = ctx.physics.add(Body::car(car_start).with_facing(90.0).with_vehicle(sounds(Vehicle::car().with_fuel(5.0, 8.0))));
50        let truck_start = level.point('T').unwrap_or(Vec3::ZERO);
51        let truck = ctx.physics.add(
52            Body::truck(truck_start).with_facing(90.0).with_vehicle(sounds(Vehicle::truck()).engine_off()),
53        );
54        let garage_at = level.point('G').unwrap_or(Vec3::ZERO);
55        let garage = ctx.physics.add(Body::sensor(garage_at).with_box(6.0, 6.0, 3.0).with_tag("garage"));
56        ctx.loop_on(garage, "garage");
57        ctx.follow(car);
58        Self { car, truck, driving: car, garage }
59    }
Source

pub fn with_horn_sound(self, name: impl Into<String>) -> Self

Sets the horn sound.

Examples found in repository?
examples/driving.rs (line 43)
29    fn new(ctx: &mut Context) -> Self {
30        // Engine: a low buzz that loops without clicks (whole cycles, no fades).
31        let engine = Synth::saw(55.0).length(1.0).attack(0.0).release(0.0).volume(0.25)
32            .with(Synth::square(110.0).length(1.0).attack(0.0).release(0.0).volume(0.08));
33        ctx.audio.register("engine", engine);
34        ctx.audio.register("horn", Synth::square(415.0).length(0.5).volume(0.25).with(Synth::square(523.0).length(0.5).volume(0.2)));
35        ctx.audio.register("shift", Synth::noise().length(0.04).decay(90.0).volume(0.3));
36        ctx.audio.register("crash", Synth::noise().length(0.4).decay(10.0).volume(0.8).with(Synth::sine(80.0).sweep_to(30.0).length(0.3)));
37        ctx.audio.register("start", Synth::saw(40.0).sweep_to(55.0).length(0.6).volume(0.3));
38        ctx.audio.register("garage", Synth::sine(880.0).length(0.15).decay(10.0));
39
40        let level = ctx.physics.build_level(MAP, 6.0);
41        let sounds = |v: Vehicle| {
42            v.with_engine_sound("engine")
43                .with_horn_sound("horn")
44                .with_shift_sound("shift")
45                .with_crash_sound("crash")
46                .with_start_sound("start")
47        };
48        let car_start = level.point('P').unwrap_or(Vec3::ZERO);
49        let car = ctx.physics.add(Body::car(car_start).with_facing(90.0).with_vehicle(sounds(Vehicle::car().with_fuel(5.0, 8.0))));
50        let truck_start = level.point('T').unwrap_or(Vec3::ZERO);
51        let truck = ctx.physics.add(
52            Body::truck(truck_start).with_facing(90.0).with_vehicle(sounds(Vehicle::truck()).engine_off()),
53        );
54        let garage_at = level.point('G').unwrap_or(Vec3::ZERO);
55        let garage = ctx.physics.add(Body::sensor(garage_at).with_box(6.0, 6.0, 3.0).with_tag("garage"));
56        ctx.loop_on(garage, "garage");
57        ctx.follow(car);
58        Self { car, truck, driving: car, garage }
59    }
Source

pub fn with_start_sound(self, name: impl Into<String>) -> Self

Sets the engine start sound.

Examples found in repository?
examples/driving.rs (line 46)
29    fn new(ctx: &mut Context) -> Self {
30        // Engine: a low buzz that loops without clicks (whole cycles, no fades).
31        let engine = Synth::saw(55.0).length(1.0).attack(0.0).release(0.0).volume(0.25)
32            .with(Synth::square(110.0).length(1.0).attack(0.0).release(0.0).volume(0.08));
33        ctx.audio.register("engine", engine);
34        ctx.audio.register("horn", Synth::square(415.0).length(0.5).volume(0.25).with(Synth::square(523.0).length(0.5).volume(0.2)));
35        ctx.audio.register("shift", Synth::noise().length(0.04).decay(90.0).volume(0.3));
36        ctx.audio.register("crash", Synth::noise().length(0.4).decay(10.0).volume(0.8).with(Synth::sine(80.0).sweep_to(30.0).length(0.3)));
37        ctx.audio.register("start", Synth::saw(40.0).sweep_to(55.0).length(0.6).volume(0.3));
38        ctx.audio.register("garage", Synth::sine(880.0).length(0.15).decay(10.0));
39
40        let level = ctx.physics.build_level(MAP, 6.0);
41        let sounds = |v: Vehicle| {
42            v.with_engine_sound("engine")
43                .with_horn_sound("horn")
44                .with_shift_sound("shift")
45                .with_crash_sound("crash")
46                .with_start_sound("start")
47        };
48        let car_start = level.point('P').unwrap_or(Vec3::ZERO);
49        let car = ctx.physics.add(Body::car(car_start).with_facing(90.0).with_vehicle(sounds(Vehicle::car().with_fuel(5.0, 8.0))));
50        let truck_start = level.point('T').unwrap_or(Vec3::ZERO);
51        let truck = ctx.physics.add(
52            Body::truck(truck_start).with_facing(90.0).with_vehicle(sounds(Vehicle::truck()).engine_off()),
53        );
54        let garage_at = level.point('G').unwrap_or(Vec3::ZERO);
55        let garage = ctx.physics.add(Body::sensor(garage_at).with_box(6.0, 6.0, 3.0).with_tag("garage"));
56        ctx.loop_on(garage, "garage");
57        ctx.follow(car);
58        Self { car, truck, driving: car, garage }
59    }
Source

pub fn with_shift_sound(self, name: impl Into<String>) -> Self

Sets the gear change sound.

Examples found in repository?
examples/driving.rs (line 44)
29    fn new(ctx: &mut Context) -> Self {
30        // Engine: a low buzz that loops without clicks (whole cycles, no fades).
31        let engine = Synth::saw(55.0).length(1.0).attack(0.0).release(0.0).volume(0.25)
32            .with(Synth::square(110.0).length(1.0).attack(0.0).release(0.0).volume(0.08));
33        ctx.audio.register("engine", engine);
34        ctx.audio.register("horn", Synth::square(415.0).length(0.5).volume(0.25).with(Synth::square(523.0).length(0.5).volume(0.2)));
35        ctx.audio.register("shift", Synth::noise().length(0.04).decay(90.0).volume(0.3));
36        ctx.audio.register("crash", Synth::noise().length(0.4).decay(10.0).volume(0.8).with(Synth::sine(80.0).sweep_to(30.0).length(0.3)));
37        ctx.audio.register("start", Synth::saw(40.0).sweep_to(55.0).length(0.6).volume(0.3));
38        ctx.audio.register("garage", Synth::sine(880.0).length(0.15).decay(10.0));
39
40        let level = ctx.physics.build_level(MAP, 6.0);
41        let sounds = |v: Vehicle| {
42            v.with_engine_sound("engine")
43                .with_horn_sound("horn")
44                .with_shift_sound("shift")
45                .with_crash_sound("crash")
46                .with_start_sound("start")
47        };
48        let car_start = level.point('P').unwrap_or(Vec3::ZERO);
49        let car = ctx.physics.add(Body::car(car_start).with_facing(90.0).with_vehicle(sounds(Vehicle::car().with_fuel(5.0, 8.0))));
50        let truck_start = level.point('T').unwrap_or(Vec3::ZERO);
51        let truck = ctx.physics.add(
52            Body::truck(truck_start).with_facing(90.0).with_vehicle(sounds(Vehicle::truck()).engine_off()),
53        );
54        let garage_at = level.point('G').unwrap_or(Vec3::ZERO);
55        let garage = ctx.physics.add(Body::sensor(garage_at).with_box(6.0, 6.0, 3.0).with_tag("garage"));
56        ctx.loop_on(garage, "garage");
57        ctx.follow(car);
58        Self { car, truck, driving: car, garage }
59    }
Source

pub fn with_crash_sound(self, name: impl Into<String>) -> Self

Sets the crash sound.

Examples found in repository?
examples/driving.rs (line 45)
29    fn new(ctx: &mut Context) -> Self {
30        // Engine: a low buzz that loops without clicks (whole cycles, no fades).
31        let engine = Synth::saw(55.0).length(1.0).attack(0.0).release(0.0).volume(0.25)
32            .with(Synth::square(110.0).length(1.0).attack(0.0).release(0.0).volume(0.08));
33        ctx.audio.register("engine", engine);
34        ctx.audio.register("horn", Synth::square(415.0).length(0.5).volume(0.25).with(Synth::square(523.0).length(0.5).volume(0.2)));
35        ctx.audio.register("shift", Synth::noise().length(0.04).decay(90.0).volume(0.3));
36        ctx.audio.register("crash", Synth::noise().length(0.4).decay(10.0).volume(0.8).with(Synth::sine(80.0).sweep_to(30.0).length(0.3)));
37        ctx.audio.register("start", Synth::saw(40.0).sweep_to(55.0).length(0.6).volume(0.3));
38        ctx.audio.register("garage", Synth::sine(880.0).length(0.15).decay(10.0));
39
40        let level = ctx.physics.build_level(MAP, 6.0);
41        let sounds = |v: Vehicle| {
42            v.with_engine_sound("engine")
43                .with_horn_sound("horn")
44                .with_shift_sound("shift")
45                .with_crash_sound("crash")
46                .with_start_sound("start")
47        };
48        let car_start = level.point('P').unwrap_or(Vec3::ZERO);
49        let car = ctx.physics.add(Body::car(car_start).with_facing(90.0).with_vehicle(sounds(Vehicle::car().with_fuel(5.0, 8.0))));
50        let truck_start = level.point('T').unwrap_or(Vec3::ZERO);
51        let truck = ctx.physics.add(
52            Body::truck(truck_start).with_facing(90.0).with_vehicle(sounds(Vehicle::truck()).engine_off()),
53        );
54        let garage_at = level.point('G').unwrap_or(Vec3::ZERO);
55        let garage = ctx.physics.add(Body::sensor(garage_at).with_box(6.0, 6.0, 3.0).with_tag("garage"));
56        ctx.loop_on(garage, "garage");
57        ctx.follow(car);
58        Self { car, truck, driving: car, garage }
59    }
Source

pub fn engine_off(self) -> Self

Starts with the engine off. Start it with Vehicle::start_engine or Context::start_engine.

Examples found in repository?
examples/driving.rs (line 52)
29    fn new(ctx: &mut Context) -> Self {
30        // Engine: a low buzz that loops without clicks (whole cycles, no fades).
31        let engine = Synth::saw(55.0).length(1.0).attack(0.0).release(0.0).volume(0.25)
32            .with(Synth::square(110.0).length(1.0).attack(0.0).release(0.0).volume(0.08));
33        ctx.audio.register("engine", engine);
34        ctx.audio.register("horn", Synth::square(415.0).length(0.5).volume(0.25).with(Synth::square(523.0).length(0.5).volume(0.2)));
35        ctx.audio.register("shift", Synth::noise().length(0.04).decay(90.0).volume(0.3));
36        ctx.audio.register("crash", Synth::noise().length(0.4).decay(10.0).volume(0.8).with(Synth::sine(80.0).sweep_to(30.0).length(0.3)));
37        ctx.audio.register("start", Synth::saw(40.0).sweep_to(55.0).length(0.6).volume(0.3));
38        ctx.audio.register("garage", Synth::sine(880.0).length(0.15).decay(10.0));
39
40        let level = ctx.physics.build_level(MAP, 6.0);
41        let sounds = |v: Vehicle| {
42            v.with_engine_sound("engine")
43                .with_horn_sound("horn")
44                .with_shift_sound("shift")
45                .with_crash_sound("crash")
46                .with_start_sound("start")
47        };
48        let car_start = level.point('P').unwrap_or(Vec3::ZERO);
49        let car = ctx.physics.add(Body::car(car_start).with_facing(90.0).with_vehicle(sounds(Vehicle::car().with_fuel(5.0, 8.0))));
50        let truck_start = level.point('T').unwrap_or(Vec3::ZERO);
51        let truck = ctx.physics.add(
52            Body::truck(truck_start).with_facing(90.0).with_vehicle(sounds(Vehicle::truck()).engine_off()),
53        );
54        let garage_at = level.point('G').unwrap_or(Vec3::ZERO);
55        let garage = ctx.physics.add(Body::sensor(garage_at).with_box(6.0, 6.0, 3.0).with_tag("garage"));
56        ctx.loop_on(garage, "garage");
57        ctx.follow(car);
58        Self { car, truck, driving: car, garage }
59    }
Source

pub fn speed(&self) -> f32

Speed along the facing in m/s, negative when reversing.

Examples found in repository?
examples/driving.rs (line 99)
71    fn update(&mut self, ctx: &mut Context) {
72        let id = self.driving;
73        ctx.drive(id);
74
75        if ctx.pressed(Key::H) {
76            ctx.horn(id);
77        }
78        if ctx.pressed(Key::E) {
79            let running = ctx.physics.vehicle(id).is_some_and(|v| v.is_engine_on());
80            if running {
81                ctx.stop_engine(id);
82                ctx.speak("Engine off");
83            } else if !ctx.start_engine(id) {
84                ctx.speak("The tank is empty");
85            }
86        }
87        if ctx.pressed(Key::Tab) {
88            if let Some(v) = ctx.physics.vehicle_mut(id) {
89                v.throttle = 0.0;
90                v.brake = 0.0;
91                v.handbrake = true;
92            }
93            self.driving = if id == self.car { self.truck } else { self.car };
94            ctx.follow(self.driving);
95            let text = format!("You switch to the {}. E starts the engine.", self.name());
96            ctx.speak(text);
97        }
98        if ctx.pressed(Key::L) && self.driving == self.truck {
99            let speed = ctx.physics.vehicle(self.truck).map_or(0.0, |v| v.speed().abs());
100            if speed > 0.5 {
101                ctx.speak("Stop first");
102            } else if let Some(v) = ctx.physics.vehicle_mut(self.truck) {
103                let load = if v.load > 0.0 { 0.0 } else { v.max_load };
104                v.set_load(load);
105                let text = format!("Load {} tons, total weight {} tons", load / 1000.0, ctx.physics.weight(self.truck) / 1000.0);
106                ctx.speak(text);
107            }
108        }
109        if ctx.pressed(Key::F)
110            && let Some(v) = ctx.physics.vehicle(id)
111        {
112            let mut text = format!("{}, gear {}", v.describe_speed(), v.gear_name());
113            if let Some(fuel) = v.fuel() {
114                text.push_str(&format!(", {fuel:.1} liters left"));
115            }
116            ctx.speak(text);
117        }
118        if ctx.pressed(Key::G) {
119            let text = ctx.physics.describe(id, self.garage);
120            ctx.speak(text);
121        }
122        if ctx.pressed(Key::F1) {
123            ctx.speak("Up gas, down brake and reverse, left and right steer, space handbrake, H horn, E engine, Tab switch vehicle, L load the truck, F speed, G garage.");
124        }
125
126        if let Some(gear) = ctx.physics.gear_changed(id)
127            && gear == -1
128        {
129            ctx.speak("Reverse");
130        }
131        if let Some((_, speed)) = ctx.physics.crashed(id)
132            && speed > 5.0
133        {
134            let text = format!("Crash at {:.0} kilometers per hour", speed * 3.6);
135            ctx.speak(text);
136        }
137        if ctx.physics.entered_tag(id, "garage").is_some() {
138            let text = format!("You parked the {} in the garage. Well done!", self.name());
139            ctx.speak(text);
140            ctx.quit();
141        }
142        if ctx.pressed(Key::Escape) {
143            ctx.quit();
144        }
145    }
Source

pub fn speed_kmh(&self) -> f32

Speed in km/h, negative when reversing.

Source

pub fn set_speed(&mut self, speed: f32)

Sets the speed in m/s, e.g. to start a race already rolling. Limited to the top speeds.

Source

pub fn describe_speed(&self) -> String

The speed ready to speak, e.g. "54 kilometers per hour" (reversing included). Always English; Lang::describe_speed uses the current language.

Examples found in repository?
examples/driving.rs (line 112)
71    fn update(&mut self, ctx: &mut Context) {
72        let id = self.driving;
73        ctx.drive(id);
74
75        if ctx.pressed(Key::H) {
76            ctx.horn(id);
77        }
78        if ctx.pressed(Key::E) {
79            let running = ctx.physics.vehicle(id).is_some_and(|v| v.is_engine_on());
80            if running {
81                ctx.stop_engine(id);
82                ctx.speak("Engine off");
83            } else if !ctx.start_engine(id) {
84                ctx.speak("The tank is empty");
85            }
86        }
87        if ctx.pressed(Key::Tab) {
88            if let Some(v) = ctx.physics.vehicle_mut(id) {
89                v.throttle = 0.0;
90                v.brake = 0.0;
91                v.handbrake = true;
92            }
93            self.driving = if id == self.car { self.truck } else { self.car };
94            ctx.follow(self.driving);
95            let text = format!("You switch to the {}. E starts the engine.", self.name());
96            ctx.speak(text);
97        }
98        if ctx.pressed(Key::L) && self.driving == self.truck {
99            let speed = ctx.physics.vehicle(self.truck).map_or(0.0, |v| v.speed().abs());
100            if speed > 0.5 {
101                ctx.speak("Stop first");
102            } else if let Some(v) = ctx.physics.vehicle_mut(self.truck) {
103                let load = if v.load > 0.0 { 0.0 } else { v.max_load };
104                v.set_load(load);
105                let text = format!("Load {} tons, total weight {} tons", load / 1000.0, ctx.physics.weight(self.truck) / 1000.0);
106                ctx.speak(text);
107            }
108        }
109        if ctx.pressed(Key::F)
110            && let Some(v) = ctx.physics.vehicle(id)
111        {
112            let mut text = format!("{}, gear {}", v.describe_speed(), v.gear_name());
113            if let Some(fuel) = v.fuel() {
114                text.push_str(&format!(", {fuel:.1} liters left"));
115            }
116            ctx.speak(text);
117        }
118        if ctx.pressed(Key::G) {
119            let text = ctx.physics.describe(id, self.garage);
120            ctx.speak(text);
121        }
122        if ctx.pressed(Key::F1) {
123            ctx.speak("Up gas, down brake and reverse, left and right steer, space handbrake, H horn, E engine, Tab switch vehicle, L load the truck, F speed, G garage.");
124        }
125
126        if let Some(gear) = ctx.physics.gear_changed(id)
127            && gear == -1
128        {
129            ctx.speak("Reverse");
130        }
131        if let Some((_, speed)) = ctx.physics.crashed(id)
132            && speed > 5.0
133        {
134            let text = format!("Crash at {:.0} kilometers per hour", speed * 3.6);
135            ctx.speak(text);
136        }
137        if ctx.physics.entered_tag(id, "garage").is_some() {
138            let text = format!("You parked the {} in the garage. Well done!", self.name());
139            ctx.speak(text);
140            ctx.quit();
141        }
142        if ctx.pressed(Key::Escape) {
143            ctx.quit();
144        }
145    }
Source

pub fn is_reversing(&self) -> bool

Whether the vehicle is rolling backwards.

Source

pub fn gear(&self) -> i32

Current gear: -1 reverse, 0 neutral (engine off), 1 and up forward.

Source

pub fn gear_name(&self) -> String

The gear ready to speak: "reverse", "neutral" or the number.

Examples found in repository?
examples/driving.rs (line 112)
71    fn update(&mut self, ctx: &mut Context) {
72        let id = self.driving;
73        ctx.drive(id);
74
75        if ctx.pressed(Key::H) {
76            ctx.horn(id);
77        }
78        if ctx.pressed(Key::E) {
79            let running = ctx.physics.vehicle(id).is_some_and(|v| v.is_engine_on());
80            if running {
81                ctx.stop_engine(id);
82                ctx.speak("Engine off");
83            } else if !ctx.start_engine(id) {
84                ctx.speak("The tank is empty");
85            }
86        }
87        if ctx.pressed(Key::Tab) {
88            if let Some(v) = ctx.physics.vehicle_mut(id) {
89                v.throttle = 0.0;
90                v.brake = 0.0;
91                v.handbrake = true;
92            }
93            self.driving = if id == self.car { self.truck } else { self.car };
94            ctx.follow(self.driving);
95            let text = format!("You switch to the {}. E starts the engine.", self.name());
96            ctx.speak(text);
97        }
98        if ctx.pressed(Key::L) && self.driving == self.truck {
99            let speed = ctx.physics.vehicle(self.truck).map_or(0.0, |v| v.speed().abs());
100            if speed > 0.5 {
101                ctx.speak("Stop first");
102            } else if let Some(v) = ctx.physics.vehicle_mut(self.truck) {
103                let load = if v.load > 0.0 { 0.0 } else { v.max_load };
104                v.set_load(load);
105                let text = format!("Load {} tons, total weight {} tons", load / 1000.0, ctx.physics.weight(self.truck) / 1000.0);
106                ctx.speak(text);
107            }
108        }
109        if ctx.pressed(Key::F)
110            && let Some(v) = ctx.physics.vehicle(id)
111        {
112            let mut text = format!("{}, gear {}", v.describe_speed(), v.gear_name());
113            if let Some(fuel) = v.fuel() {
114                text.push_str(&format!(", {fuel:.1} liters left"));
115            }
116            ctx.speak(text);
117        }
118        if ctx.pressed(Key::G) {
119            let text = ctx.physics.describe(id, self.garage);
120            ctx.speak(text);
121        }
122        if ctx.pressed(Key::F1) {
123            ctx.speak("Up gas, down brake and reverse, left and right steer, space handbrake, H horn, E engine, Tab switch vehicle, L load the truck, F speed, G garage.");
124        }
125
126        if let Some(gear) = ctx.physics.gear_changed(id)
127            && gear == -1
128        {
129            ctx.speak("Reverse");
130        }
131        if let Some((_, speed)) = ctx.physics.crashed(id)
132            && speed > 5.0
133        {
134            let text = format!("Crash at {:.0} kilometers per hour", speed * 3.6);
135            ctx.speak(text);
136        }
137        if ctx.physics.entered_tag(id, "garage").is_some() {
138            let text = format!("You parked the {} in the garage. Well done!", self.name());
139            ctx.speak(text);
140            ctx.quit();
141        }
142        if ctx.pressed(Key::Escape) {
143            ctx.quit();
144        }
145    }
Source

pub fn rpm(&self) -> f32

Engine speed in revolutions per minute (0 when the engine is off).

Source

pub fn rpm_fraction(&self) -> f32

Engine speed from 0.0 (idle) to 1.0 (highest rpm).

Source

pub fn engine_pitch(&self) -> f32

A playback pitch for a looping engine sound recorded at idle: 0.8 at idle, 2.0 at the highest rpm. The engine sound set with Vehicle::with_engine_sound uses it automatically.

Source

pub fn is_engine_on(&self) -> bool

Whether the engine runs.

Examples found in repository?
examples/driving.rs (line 79)
71    fn update(&mut self, ctx: &mut Context) {
72        let id = self.driving;
73        ctx.drive(id);
74
75        if ctx.pressed(Key::H) {
76            ctx.horn(id);
77        }
78        if ctx.pressed(Key::E) {
79            let running = ctx.physics.vehicle(id).is_some_and(|v| v.is_engine_on());
80            if running {
81                ctx.stop_engine(id);
82                ctx.speak("Engine off");
83            } else if !ctx.start_engine(id) {
84                ctx.speak("The tank is empty");
85            }
86        }
87        if ctx.pressed(Key::Tab) {
88            if let Some(v) = ctx.physics.vehicle_mut(id) {
89                v.throttle = 0.0;
90                v.brake = 0.0;
91                v.handbrake = true;
92            }
93            self.driving = if id == self.car { self.truck } else { self.car };
94            ctx.follow(self.driving);
95            let text = format!("You switch to the {}. E starts the engine.", self.name());
96            ctx.speak(text);
97        }
98        if ctx.pressed(Key::L) && self.driving == self.truck {
99            let speed = ctx.physics.vehicle(self.truck).map_or(0.0, |v| v.speed().abs());
100            if speed > 0.5 {
101                ctx.speak("Stop first");
102            } else if let Some(v) = ctx.physics.vehicle_mut(self.truck) {
103                let load = if v.load > 0.0 { 0.0 } else { v.max_load };
104                v.set_load(load);
105                let text = format!("Load {} tons, total weight {} tons", load / 1000.0, ctx.physics.weight(self.truck) / 1000.0);
106                ctx.speak(text);
107            }
108        }
109        if ctx.pressed(Key::F)
110            && let Some(v) = ctx.physics.vehicle(id)
111        {
112            let mut text = format!("{}, gear {}", v.describe_speed(), v.gear_name());
113            if let Some(fuel) = v.fuel() {
114                text.push_str(&format!(", {fuel:.1} liters left"));
115            }
116            ctx.speak(text);
117        }
118        if ctx.pressed(Key::G) {
119            let text = ctx.physics.describe(id, self.garage);
120            ctx.speak(text);
121        }
122        if ctx.pressed(Key::F1) {
123            ctx.speak("Up gas, down brake and reverse, left and right steer, space handbrake, H horn, E engine, Tab switch vehicle, L load the truck, F speed, G garage.");
124        }
125
126        if let Some(gear) = ctx.physics.gear_changed(id)
127            && gear == -1
128        {
129            ctx.speak("Reverse");
130        }
131        if let Some((_, speed)) = ctx.physics.crashed(id)
132            && speed > 5.0
133        {
134            let text = format!("Crash at {:.0} kilometers per hour", speed * 3.6);
135            ctx.speak(text);
136        }
137        if ctx.physics.entered_tag(id, "garage").is_some() {
138            let text = format!("You parked the {} in the garage. Well done!", self.name());
139            ctx.speak(text);
140            ctx.quit();
141        }
142        if ctx.pressed(Key::Escape) {
143            ctx.quit();
144        }
145    }
Source

pub fn start_engine(&mut self) -> bool

Starts the engine (silently; Context::start_engine also plays the start sound). Returns false if the tank is empty.

Source

pub fn stop_engine(&mut self)

Stops the engine. The vehicle rolls out.

Source

pub fn fuel(&self) -> Option<f32>

Liters left in the tank, None for unlimited fuel.

Examples found in repository?
examples/driving.rs (line 113)
71    fn update(&mut self, ctx: &mut Context) {
72        let id = self.driving;
73        ctx.drive(id);
74
75        if ctx.pressed(Key::H) {
76            ctx.horn(id);
77        }
78        if ctx.pressed(Key::E) {
79            let running = ctx.physics.vehicle(id).is_some_and(|v| v.is_engine_on());
80            if running {
81                ctx.stop_engine(id);
82                ctx.speak("Engine off");
83            } else if !ctx.start_engine(id) {
84                ctx.speak("The tank is empty");
85            }
86        }
87        if ctx.pressed(Key::Tab) {
88            if let Some(v) = ctx.physics.vehicle_mut(id) {
89                v.throttle = 0.0;
90                v.brake = 0.0;
91                v.handbrake = true;
92            }
93            self.driving = if id == self.car { self.truck } else { self.car };
94            ctx.follow(self.driving);
95            let text = format!("You switch to the {}. E starts the engine.", self.name());
96            ctx.speak(text);
97        }
98        if ctx.pressed(Key::L) && self.driving == self.truck {
99            let speed = ctx.physics.vehicle(self.truck).map_or(0.0, |v| v.speed().abs());
100            if speed > 0.5 {
101                ctx.speak("Stop first");
102            } else if let Some(v) = ctx.physics.vehicle_mut(self.truck) {
103                let load = if v.load > 0.0 { 0.0 } else { v.max_load };
104                v.set_load(load);
105                let text = format!("Load {} tons, total weight {} tons", load / 1000.0, ctx.physics.weight(self.truck) / 1000.0);
106                ctx.speak(text);
107            }
108        }
109        if ctx.pressed(Key::F)
110            && let Some(v) = ctx.physics.vehicle(id)
111        {
112            let mut text = format!("{}, gear {}", v.describe_speed(), v.gear_name());
113            if let Some(fuel) = v.fuel() {
114                text.push_str(&format!(", {fuel:.1} liters left"));
115            }
116            ctx.speak(text);
117        }
118        if ctx.pressed(Key::G) {
119            let text = ctx.physics.describe(id, self.garage);
120            ctx.speak(text);
121        }
122        if ctx.pressed(Key::F1) {
123            ctx.speak("Up gas, down brake and reverse, left and right steer, space handbrake, H horn, E engine, Tab switch vehicle, L load the truck, F speed, G garage.");
124        }
125
126        if let Some(gear) = ctx.physics.gear_changed(id)
127            && gear == -1
128        {
129            ctx.speak("Reverse");
130        }
131        if let Some((_, speed)) = ctx.physics.crashed(id)
132            && speed > 5.0
133        {
134            let text = format!("Crash at {:.0} kilometers per hour", speed * 3.6);
135            ctx.speak(text);
136        }
137        if ctx.physics.entered_tag(id, "garage").is_some() {
138            let text = format!("You parked the {} in the garage. Well done!", self.name());
139            ctx.speak(text);
140            ctx.quit();
141        }
142        if ctx.pressed(Key::Escape) {
143            ctx.quit();
144        }
145    }
Source

pub fn fuel_fraction(&self) -> f32

Tank level from 0.0 (empty) to 1.0 (full); always 1.0 for unlimited fuel.

Source

pub fn is_out_of_fuel(&self) -> bool

Whether the tank is empty (never with unlimited fuel).

Source

pub fn refuel(&mut self, liters: f32) -> f32

Adds fuel in liters, up to the tank size. Returns how much was added.

Source

pub fn set_load(&mut self, kg: f32) -> f32

Sets the cargo in kilograms, limited to 0..=Vehicle::max_load. Returns the new load.

Examples found in repository?
examples/driving.rs (line 104)
71    fn update(&mut self, ctx: &mut Context) {
72        let id = self.driving;
73        ctx.drive(id);
74
75        if ctx.pressed(Key::H) {
76            ctx.horn(id);
77        }
78        if ctx.pressed(Key::E) {
79            let running = ctx.physics.vehicle(id).is_some_and(|v| v.is_engine_on());
80            if running {
81                ctx.stop_engine(id);
82                ctx.speak("Engine off");
83            } else if !ctx.start_engine(id) {
84                ctx.speak("The tank is empty");
85            }
86        }
87        if ctx.pressed(Key::Tab) {
88            if let Some(v) = ctx.physics.vehicle_mut(id) {
89                v.throttle = 0.0;
90                v.brake = 0.0;
91                v.handbrake = true;
92            }
93            self.driving = if id == self.car { self.truck } else { self.car };
94            ctx.follow(self.driving);
95            let text = format!("You switch to the {}. E starts the engine.", self.name());
96            ctx.speak(text);
97        }
98        if ctx.pressed(Key::L) && self.driving == self.truck {
99            let speed = ctx.physics.vehicle(self.truck).map_or(0.0, |v| v.speed().abs());
100            if speed > 0.5 {
101                ctx.speak("Stop first");
102            } else if let Some(v) = ctx.physics.vehicle_mut(self.truck) {
103                let load = if v.load > 0.0 { 0.0 } else { v.max_load };
104                v.set_load(load);
105                let text = format!("Load {} tons, total weight {} tons", load / 1000.0, ctx.physics.weight(self.truck) / 1000.0);
106                ctx.speak(text);
107            }
108        }
109        if ctx.pressed(Key::F)
110            && let Some(v) = ctx.physics.vehicle(id)
111        {
112            let mut text = format!("{}, gear {}", v.describe_speed(), v.gear_name());
113            if let Some(fuel) = v.fuel() {
114                text.push_str(&format!(", {fuel:.1} liters left"));
115            }
116            ctx.speak(text);
117        }
118        if ctx.pressed(Key::G) {
119            let text = ctx.physics.describe(id, self.garage);
120            ctx.speak(text);
121        }
122        if ctx.pressed(Key::F1) {
123            ctx.speak("Up gas, down brake and reverse, left and right steer, space handbrake, H horn, E engine, Tab switch vehicle, L load the truck, F speed, G garage.");
124        }
125
126        if let Some(gear) = ctx.physics.gear_changed(id)
127            && gear == -1
128        {
129            ctx.speak("Reverse");
130        }
131        if let Some((_, speed)) = ctx.physics.crashed(id)
132            && speed > 5.0
133        {
134            let text = format!("Crash at {:.0} kilometers per hour", speed * 3.6);
135            ctx.speak(text);
136        }
137        if ctx.physics.entered_tag(id, "garage").is_some() {
138            let text = format!("You parked the {} in the garage. Well done!", self.name());
139            ctx.speak(text);
140            ctx.quit();
141        }
142        if ctx.pressed(Key::Escape) {
143            ctx.quit();
144        }
145    }
Source

pub fn distance(&self) -> f32

Meters driven so far (forward and backward), like an odometer.

Trait Implementations§

Source§

impl Clone for Vehicle

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Vehicle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Vehicle

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Vehicle

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Vehicle

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more