Skip to content

Commit

Permalink
String -> Arc<str>
Browse files Browse the repository at this point in the history
  • Loading branch information
Kharif committed Jan 31, 2025
1 parent eb6b9d5 commit 5ed711c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
13 changes: 7 additions & 6 deletions examples/flip_cards/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use rust_search::SearchBuilder;
use serde_json::{Map, Value};
use std::collections::{HashSet, VecDeque};
use std::fs;
use std::sync::Arc;

// Function to find and extract flip cards from JSON data
fn find_flip_cards(value: &Value) -> Vec<Value> {
Expand Down Expand Up @@ -74,8 +75,8 @@ fn find_flip_cards(value: &Value) -> Vec<Value> {
#[derive(Clone)]
struct FlipCardState {
show_answer: bool,
question: String,
answer: String,
question: Arc<str>,
answer: Arc<str>,
}

// Struct to represent the state of all flip cards
Expand Down Expand Up @@ -114,8 +115,8 @@ fn main() {
.iter()
.map(|card| FlipCardState {
show_answer: false,
question: card["q"].as_str().unwrap().to_string(),
answer: card["a"].as_str().unwrap().to_string(),
question: card["q"].to_string().into(),
answer: card["a"].to_string().into(),
})
.collect(),
current_index: 0, // Start at the first card
Expand All @@ -128,9 +129,9 @@ fn main() {
// Render the current flip card
vstack((
text(if current_card.show_answer {
current_card.answer.as_str()
&current_card.answer
} else {
current_card.question.as_str()
&current_card.question
})
.font_size(12)
.padding(Auto),
Expand Down
13 changes: 5 additions & 8 deletions src/views/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ macro_rules! impl_text {
let txt = &format!("{}", self);
let vger = &mut args.vger;
let origin = vger.text_bounds(txt, Text::DEFAULT_SIZE, None).origin;

vger.save();
vger.translate([-origin.x, -origin.y]);
vger.text(txt, Text::DEFAULT_SIZE, TEXT_COLOR, None);
Expand All @@ -116,7 +116,7 @@ macro_rules! impl_text {
let txt = &format!("{}", self);
(args.text_bounds)(txt, Text::DEFAULT_SIZE, None).size
}

fn access(
&self,
path: &mut IdPath,
Expand All @@ -131,8 +131,7 @@ macro_rules! impl_text {
}
}

impl TextModifiers for $ty
{
impl TextModifiers for $ty {
fn font_size(self, size: u32) -> Text {
Text {
text: format!("{}", self),
Expand All @@ -159,8 +158,7 @@ macro_rules! impl_text {
}
}
}

}
};
}

// XXX: this used to be generic for any Display but
Expand Down Expand Up @@ -205,8 +203,7 @@ impl DynView for &'static str {
}
}

impl TextModifiers for &'static str
{
impl TextModifiers for &'static str {
fn font_size(self, size: u32) -> Text {
Text {
text: format!("{}", self),
Expand Down

0 comments on commit 5ed711c

Please sign in to comment.