traits Questions

3

Solved

Rust supports trait inheritance, as follows: pub trait A {} pub trait B: A {} B: A means that if some type T implements B, it also needs to implement all the methods in A. But today I see the foll...
Bucky asked 10/11, 2021 at 8:59

2

Solved

I'm wondering if there is any good reason why this behaviour is possible in the current PHP 5.4 implementation: trait T { public function test(PDO $pdo) {} } class C { use T; public function t...
Satanism asked 17/7, 2012 at 11:21

9

I'm new to traits, but thought I'd give it a try. But, it doesn't seem to load. I've created a trait within a folder under the Laravel app directory: app\Helpers called CheckPermsAgainstObjectTrai...
Developer asked 29/5, 2016 at 15:49

2

Solved

The solution from How do I store a variable of type `impl Trait` in a struct? suggests creating a Future trait object. Doing that in my real code generates an error that the type is not Send, but t...
Swink asked 25/11, 2019 at 17:34

2

Solved

I've search all over this site and google and I ended up creating this account... I need some help with php, traits and classes. I have this 2 different traits, that have some methods with the same...
Heddie asked 11/5, 2014 at 17:23

3

Trying to compile the following Rust code mod traits { pub trait Dog { fn bark(&self) { println!("Bow"); } } } struct Dog; impl traits::Dog for Dog {} fn main() { let dog = Dog; dog....
Cookery asked 6/6, 2015 at 17:18

2

I have: struct Plumbus<'a> { grumbo: &'a dyn Grumbo, } trait Grumbo { fn dinglebop<T>(&self, x: &mut T) -> bool { false } } but I get: error[E0038]: the trait `Grumbo...
Reber asked 21/4, 2018 at 5:18

4

Solved

I want to exclude all inherited methods from trait(s) from the list that are not overriden in a class So how to know if a class member is inherited from trait? Yes, I can check it like this: if ...
Dustpan asked 5/6, 2015 at 8:38

4

Solved

I just took the dive into Rust and want to make some basic math functions that are generic. I have the following is_prime function: fn is_prime(n: i64) -> bool { if n == 2 || n == 3 { return ...
Kapoor asked 7/11, 2014 at 22:1

3

I have a struct NotificationOption and another struct NotificationOption2 as well as an implementation for From<NotificationOption> for NotificationOption2. I'm would like to convert Vec<N...
Phytobiology asked 16/12, 2020 at 18:23

2

Solved

Is it possible to require that a struct have a particular field as part of a trait? I am doing some web automation in Rust with the thirtyfour_sync crate. I want to write some traits with default i...
Potamic asked 29/6, 2021 at 2:31

1

Solved

To familiarize myself with Rust, I took it upon myself to write a bloom filter that is backed by a BitVec. Part of that will include a save method that serializes the whole struct using serde and w...
Piegari asked 13/2 at 21:12

1

Solved

I am trying to make work a trait that depends on multiple levels of other abstract traits. I am running into this error: error[E0391]: cycle detected when checking effective visibilities | note: ....
Ujiji asked 26/1 at 20:53

2

Solved

I created a simple project for educational purpose, so I have a main function and 3 traits Battery, Display and GSM and implementations for them. I want the the main function to be in file main.rs ...
Rafaellle asked 3/6, 2016 at 8:56

5

Solved

Is it at all possible to define functions inside of traits as having impl Trait return types? I want to create a trait that can be implemented by multiple structs so that the new() functions of all...
Gallinacean asked 14/9, 2016 at 3:38

6

Solved

Given a lambda, is it possible to figure out it's parameter type and return type? If yes, how? Basically, I want lambda_traits which can be used in following ways: auto lambda = [](int i) { retur...
Demmer asked 30/10, 2011 at 5:47

3

Solved

I have seen an example on Stackexchange (please note the trait accessing the class property): trait CheckPermissionTrait { protected function checkPermission($object_id) { $judge = $this-&gt...
Goethe asked 11/5, 2016 at 9:24

1

Solved

I just build a trait Bar with 2 functions (alpha() with implementation and beta() with only interfaces), and I hope the struct who implement Bar implements only beta(), and never implement their ow...
Sandrocottus asked 28/11, 2023 at 8:4

3

How can I simplify this code? I still can't wrap my head around rust's traits and structs after OOP. struct Player { entity: Entity, hp: i32, atk: i32 } struct Chest { entity: Entity, amount:...
Exorcist asked 21/4, 2022 at 20:24

2

Solved

Is it possible to define fmt::Display and fmt::Debug together, i.e. such that they use the same implementation? Assume we have the below sample code (purely for demonstration purposes): use std::fm...
Ecumenicist asked 14/11, 2021 at 15:12

10

Notice that a trait may use other traits, so the class may not be using that trait directly. And also the class may be inherited from a parent class who is the one uses the trait. Is this a questi...
Eleonoreeleoptene asked 14/9, 2017 at 11:33

2

Solved

I have a proc-macro crate with a macro that, when expanded, needs to use custom trait implementations for Rust built-in types. I tried to define the trait in the same crate, but Rust tells me that ...
Wivinah asked 9/10, 2020 at 23:18

1

Say I have a Julia trait that relates to two types: one type is a sort of "base" type that may satisfy a sort of partial trait, and the other is an associated type that is uniquely determ...
Teeters asked 24/2, 2016 at 22:19

4

Solved

In traditional object-oriented languages (e.g. Java), it is possible to "extend" the functionality of a method in an inherited class by calling the original method from the super class in the overr...
Uchish asked 16/7, 2015 at 18:31

3

Solved

I have a trait Foo, with some implementations, together with an enum Foos with one variant per implemention. I want to be able to convert my enum into Box<dyn Foo>. This is my current soluti...
Vishinsky asked 5/1, 2019 at 21:58

© 2022 - 2024 — McMap. All rights reserved.