This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::cell::{Cell, RefCell}; | |
use std::rc::Rc; | |
type RefNode = Rc<NodeTrait>; | |
trait NodeTrait { | |
fn id(&self) -> usize { | |
0 | |
} | |
fn set_id(&self, id: usize); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::cell::RefCell; | |
use std::rc::Rc; | |
trait NodeTrait { | |
fn get_x(&self) -> f32; | |
fn add(&mut self, v: f32); | |
fn step(&mut self); | |
fn process(&mut self); | |
fn replacement(&self) -> &Option<RNode> { | |
&None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// See this users response | |
// https://users.rust-lang.org/t/typical-cant-borrow-issue/24817 | |
trait NodeTrait { | |
fn get_x(&self) -> f32; | |
fn add(&mut self, v: f32); | |
fn step(&mut self); | |
fn process(&mut self); | |
fn print(&self) { | |
println!("node: {}", self.get_x()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::cell::RefCell; | |
use std::rc::Rc; | |
type RefNode = Rc<RefCell<NodeTrait>>; | |
type RefTransform = Rc<RefCell<TransformProperty>>; | |
trait NodeTrait { | |
fn id(&self) -> usize { | |
0 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://www.snoyman.com/blog/2018/11/rust-crash-course-05-rule-of-three | |
#[derive(Debug)] | |
struct Person { | |
name: String, | |
age: u32, | |
} | |
fn birthday_immutable(person: &mut Person) { | |
person.age += 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// How to extract Option from Cell | |
pub struct X { | |
replacement: Cell<Option<usize>>, | |
... | |
} | |
fn get_transition_node(&self) -> usize { | |
if let Some(rep) = &*self.replacement.borrow() { | |
let repl = rep.borrow(); | |
return repl.data().borrow().node.id(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 4bit up counter - top.v | |
// This is expects a pcf specific to the tinyFPGA-B2 board | |
module top ( | |
pin1_usb_dp, // USB pull-up enable, set low to disable | |
pin2_usb_dn, | |
pin3_clk_16mhz, // 16 MHz on-board clock | |
pin13, // Reset, active high, synchonous reset input | |
pin12, // Enable, active high on counter | |
pin11, // MSB output pin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// shift_register - top.v | |
// | |
// Description: | |
// shifts bits to left | |
// Pins are defined in pins.pcf file. | |
// | |
// out <-- pin13, pin12, pin11, pin10...,pin6 <-- pin5 in | |
module top ( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// cylon effect - top.v | |
// | |
// pins are relative to the tinyFPGA-B2 | |
// I really need to stop using reg bits and use a vector. <-- lazy person. | |
module top ( | |
output pin1_usb_dp,// USB pull-up enable, set low to disable | |
output pin2_usb_dn, | |
input pin3_clk_16mhz, // 16 MHz on-board clock | |
output pin13, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// cylon effect - top.v | |
// | |
// pins are relative to the tinyFPGA-B2 | |
module top ( | |
output pin1_usb_dp,// USB pull-up enable, set low to disable | |
output pin2_usb_dn, | |
input pin3_clk_16mhz, // 16 MHz on-board clock | |
output pin13, | |
output pin12, |
OlderNewer