traits Questions
2
Solved
I have the following trait:
trait ARCacheableTrait
{
public function instantiate() {
// this will need to call some ActiveRecord methods using parent::
}
}
It's purpose is to override the ins...
3
I just came across the problem of implementing a trait I do not own for a type I do not own. Then I googled the exact How do I implement a trait I don't own for a type I don't own? question.
The th...
1
Solved
I've been learning Rust recently and am working on a 3d engine using glfw3 and gl. I've got as far as trying to get a shader program that worked in my C++ engine working on my Rust one but have hit...
2
Solved
I am learning Rust and want to dive into marker traits. Definition from official documentation is not clear for me: https://doc.rust-lang.org/std/marker/index.html
Definition:
Primitive traits and...
6
Solved
I'm new to Scala (came from Ruby world).
And I was curious about "traits" concept in Scala (which should be ~similar to modules in ruby, if I understand it correctly).
And here's a use case.
Sup...
Denti asked 7/11, 2014 at 22:49
4
Solved
I have a distributed system defined by a sort of "state machine" ( "flow chart" )
each system writes there state in a shared "log"
I'm representing each state as part of a sealed trait and a give...
Sledge asked 3/9, 2019 at 14:48
2
Say I have a test:
[Theory]
[InlineData("one")]
[InlineData("two")]
public void ShouldSelectSingleTheoryFromDotnetTest(string s)
{
Assert.True(true);
}
I want to execute...
Konyn asked 25/1, 2021 at 12:41
2
Solved
Is it OK to use properties/methods from parent classes in trait methods?
This code works, but is it good practice?
class Child extends Base{
use ExampleTrait;
public function __construct(){
...
3
Solved
How can I deal with traits with methods of same name?
trait FooTrait {
public function fooMethod() {
return 'foo method';
}
public function getRow() {
return 'foo row';
}
}
trait TooTrait...
5
Example #2 from PHP manual http://php.net/manual/en/language.oop5.traits.php states
<?php
class Base {
public function sayHello() {
echo 'Hello ';
}
}
trait SayWorld {
public function sayH...
Knee asked 21/10, 2012 at 21:58
2
In Rust, you can cast from Arc/Box/Rc<T> to Arc/Box/Rc<dyn Trait> using some sort of compiler magic accessed with the as keyword. Is there a way to opt into this magic for a user-define...
2
Solved
I wan't to execute constructor in my trait (or another method while trait is used). Is it possible?
trait test{
public function __construct()
{
echo 'test';
}
}
class myClass{
use test;
pub...
1
I'm writing a function that accepts different trait implementors. One of them is a closure. Some closures need an argument type annotation and some don't, depending on their bodies.
Example (playg...
2
Solved
I am trying to understand why the following code does not compile:
trait Vehicle {
fn get_num_wheels(&self) -> u32;
}
impl std::fmt::Display for dyn Vehicle {
fn fmt(&self, f: &mu...
1
I will try to simplify the problem as much as I can.
I want to disable a relation load from a trait on a resource that happens at the retrieved event.
There is a model we will name Post that uses a...
Concinnous asked 1/2, 2023 at 11:54
3
Solved
In a PHP trait, can I use self as the return type of a method? Will it reference the class that imports the trait?
<?php
declare(strict_types=1);
trait MyTrait
{
public function setSomething...
Dingo asked 3/8, 2020 at 10:33
4
Solved
Recent Rust changes have made "trait objects" more prominent to me, but I only have a nebulous grasp of what actually makes something into a trait object. One change in particular is the upcoming c...
Neysa asked 19/12, 2014 at 14:14
2
Solved
I see this a lot in Rust code. Here are a few examples from the standard library:
impl<T> const Default for Option<T> {...}
impl const From<char> for u64 {...}
What is impl cons...
3
Solved
Can you call a trait static method implemented by types from another trait static method implemented in the trait? For example:
trait SqlTable {
fn table_name() -> String;
fn load(id: i32) -...
1
Solved
I'm trying to use the Diesel crate (version 2.0.2; rustc 1.63.0) for an application and have some code that goes like this:
src/models.rs
use uuid::Uuid;
use diesel::prelude::*;
use crate::schema:...
Perfidious asked 8/12, 2022 at 11:36
2
Solved
I am trying to implement a trait for types such that the reference to the type is convertible into an iterator with Item implementing a specific trait
Specifically, consider the following code:
str...
3
Solved
I wanted to implement the Shl trait for Vec, the code is below. This would make things like vec << 4 possible, which would be nice sugar for vec.push(4).
use std::ops::Shl;
impl<T> Sh...
3
Solved
I'm using Rocket framework and I want to make an async HTTP request in my handler, something like this
#[get("/")]
async fn handler() -> String {
some_func().await;
"OK".into()
}
And as a r...
Bortz asked 20/4, 2020 at 13:37
4
Solved
I'm trying to create a function that returns an instance of the Shader trait. Here is my drastically simplified code:
trait Shader {}
struct MyShader;
impl Shader for MyShader {}
struct Graphics...
3
Solved
I found in the library reference for std::rc::Rc this trait implementation
impl<T> !Send for Rc<T>
where
T: ?Sized,
What does the exclamation point in front of Send mean?
I cons...
© 2022 - 2024 — McMap. All rights reserved.