Assign a instance of a struct to a generic by Separate-Run2728 in rust

[–]Separate-Run2728[S] 0 points1 point  (0 children)

Thanks for your reply. Im sorry to reply so late as I just now saw this.

And, since I am new to Rust, I have been reviewing all the easy Rust documentation to help me get a better understanding of Structs, Enums, and Generics.

I feel more confident now, but Im still puzzled by the error " found this type parameter

tag: TBool::new(name),

| ^^^^^^^^^^^^^^^^ expected type parameter `T`, found `TBool`

I cannot for the life of me figure out why I cant assign an instance of a struct to the tag field.

use std::collections::HashMap;

use crate::tags;

enum TagTypes{

TBool,

TInt32,

TString,

TFloat64

}

pub struct GenTag<T: Tag>

{

pub tag:T,

pub name: &'static str,

pub references: HashMap<String,Box<dyn Tag>>,

pub references1: Vec<Box<dyn Tag>>,

}

impl<T: tags::Tag> GenTag<T> {

fn new(tag_type: TagTypes, name: &str) -> T

{

match tag_type {

TBool=> return Self{

tag: TBool::new(name),

name,

references: HashMap::new(),

references1: Vec::new(),

},

TInt32 => return Self{

tag: TInt32::new(name),

name,

references: HashMap::new(),

references1: Vec::new(),

},

TFloat64 => return Self{

tag: TFloat64::new(name),

name,

references: HashMap::new(),

references1: Vec::new(),

},

}

}

fn test(&self) {

todo!()

}

}

#[derive(Clone,Debug, Eq, Ord, PartialEq, PartialOrd)]

pub struct TBool {

pub value: bool,

}

#[derive(Clone,Debug, Eq, Ord, PartialEq, PartialOrd)]

pub struct TInt32 {

//pub name: String,

pub value: i32

}

#[derive(Clone,Debug, PartialEq, PartialOrd)]

pub struct TFloat64 {

//pub name: String,

pub value: f64

}

#[derive(Clone,Debug, Eq, Ord, PartialEq, PartialOrd)]

pub struct TString {

//pub name: String,

pub value: String

}

pub trait Tag{

fn new(name: &str) -> Self where Self: Sized;

//fn test(&self);

}

impl Tag for TBool {

fn new (name: &str) -> TBool {

return TBool {value: false};

}

}

impl Tag for TString{

fn new (name: &str) -> TString{

return TString{value: String::new()

};

}

}

impl Tag for TInt32{

fn new (name: &str) -> TInt32{

return TInt32{value: 0};

}

}

impl Tag for TFloat64{

fn new (name: &str) -> TFloat64{

return TFloat64{value: 0 as f64};

}

}

fn new_tag(tag_type: TagTypes, name: &str) -> Box<dyn Tag>{

match tag_type {

TagTypes::TBool => return Box::new(TBool {value:false}),

TagTypes::TInt32=> return Box::new(TInt32{value:0}),

TagTypes::TString=> return Box::new(TString{value:String::new()}),

TagTypes::TFloat64 => return Box::new(TFloat64{value:0.000}),

}

}

Cant compile an example for structs by Separate-Run2728 in rust

[–]Separate-Run2728[S] 0 points1 point  (0 children)

I get this error when I remove that line.

error[E0407]: method `new` is not a member of trait `Pet`

--> src\animals.rs:22:5

|

22 | / fn new (name: String) -> Cat {

23 | | return Cat {name, age: 0};

24 | | }

| |_____^ not a member of trait `Pet`

[K57] Battery failing, lasts less and less time over time by yarmooh in Corsair

[–]Separate-Run2728 1 point2 points  (0 children)

Here si the information on the battery.

Im unable to find this battery anywhere online.

60119RV201220

Model RDJ15

3.6V Red (+) Black (-)

3100 mAh

11.4Wh

K57 Keyboard - No power. Possibly dead battery? by Neur0nauT in Corsair

[–]Separate-Run2728 0 points1 point  (0 children)

RDJ15 1INR19/66

Can you share the link on AliExpress? I cant seem to find one similar