// For shared state across tasks, these are your main tools:
struct MyService {
// Immutable shared state
config: Arc<Config>,
// Mutable shared state
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::collections::{HashMap, HashSet}; | |
use std::hash::Hash; | |
pub struct Collection<'a, T> { | |
items: Vec<&'a T>, | |
} | |
impl<'a, T> Collection<'a, T> { | |
pub fn new(items: &'a [T]) -> Self { | |
Self { |
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::sync::Arc; | |
use tokio::sync::{broadcast, Mutex}; | |
use tokio::time::{sleep, Duration}; | |
#[derive(Debug)] | |
struct SharedContext { | |
counter: i32, | |
last_updated_by: String, | |
} |
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::sync::Arc; | |
use tokio::sync::Mutex; | |
use tokio::time::{sleep, Duration}; | |
// Our shared context that will be accessed by all workers | |
#[derive(Debug)] | |
struct SharedContext { | |
counter: i32, | |
last_updated_by: String, | |
} |
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 rand::Rng; | |
use std::io::{self, Write}; | |
#[derive(Debug, Default)] | |
struct Score { | |
player: u32, | |
computer: u32, | |
} | |
#[derive(Debug, PartialEq, Clone, Copy)] |
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 rand::Rng; | |
use std::io::{self, Write}; | |
#[derive(Debug)] | |
struct Score { | |
player: u32, | |
computer: u32, | |
} | |
#[derive(Debug, PartialEq, Clone)] |
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
defmodule RPS do | |
defmodule Score, do: defstruct player: 0, computer: 0 | |
defmodule Context do | |
defstruct [ | |
score: %Score{}, | |
rounds_to_play: 3, | |
valid_moves: [:rock, :paper, :scissors], | |
win_conditions: %{rock: :scissors, paper: :rock, scissors: :paper}, | |
io: IO |
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
defmodule RPS do | |
defmodule Score, do: defstruct player: 0, computer: 0 | |
def play do | |
%Score{} | |
|> Stream.iterate(&play_round/1) | |
|> Enum.at(3) | |
|> announce_winner() | |
|> maybe_play_again() | |
end |
People
![]() :bowtie: |
π :smile: |
π :laughing: |
---|---|---|
π :blush: |
π :smiley: |
:relaxed: |
π :smirk: |
π :heart_eyes: |
π :kissing_heart: |
π :kissing_closed_eyes: |
π³ :flushed: |
π :relieved: |
π :satisfied: |
π :grin: |
π :wink: |
π :stuck_out_tongue_winking_eye: |
π :stuck_out_tongue_closed_eyes: |
π :grinning: |
π :kissing: |
π :kissing_smiling_eyes: |
π :stuck_out_tongue: |
NewerOlder