choose_your_bed

Crates.iochoose_your_bed
lib.rschoose_your_bed
version69.0.38
created_at2026-01-23 11:05:33.295215+00
updated_at2026-01-23 11:05:33.295215+00
descriptionHigh-quality integration for https://supermaker.ai/blog/how-to-make-the-viral-choose-your-bed-videos-with-ai/
homepagehttps://supermaker.ai/blog/how-to-make-the-viral-choose-your-bed-videos-with-ai/
repositoryhttps://github.com/qy-upup/choose-your-bed
max_upload_size
id2064163
size13,905
(qy-upup)

documentation

README

choose-your-bed

A Rust crate for simulating the "Choose Your Bed" video trend, allowing programmatic generation of bed selection scenarios. This library provides a flexible framework for defining bed characteristics and user preferences, enabling the creation of diverse and engaging simulations.

Installation

Add the following to your Cargo.toml file: toml [dependencies] choose-your-bed = "0.1.0" # Replace with the latest version

Usage

Here are a few examples of how to use the choose-your-bed crate:

1. Basic Bed Selection: rust use choose_your_bed::{Bed, Preference, choose_bed};

fn main() { let beds = vec![ Bed { comfort: 8, firmness: 3, price: 500.0 }, Bed { comfort: 5, firmness: 7, price: 750.0 }, Bed { comfort: 9, firmness: 2, price: 600.0 }, ];

let preferences = vec![
    Preference { attribute: "comfort".to_string(), weight: 0.6 },
    Preference { attribute: "firmness".to_string(), weight: 0.4 },
    Preference { attribute: "price".to_string(), weight: -0.2 },
];

let best_bed = choose_bed(&beds, &preferences).unwrap();

println!("The best bed for you is: {:?}", best_bed);

}

2. Considering Budget Constraints: rust use choose_your_bed::{Bed, Preference, choose_bed};

fn main() { let beds = vec![ Bed { comfort: 7, firmness: 4, price: 400.0 }, Bed { comfort: 6, firmness: 6, price: 600.0 }, Bed { comfort: 9, firmness: 3, price: 800.0 }, ];

let preferences = vec![
    Preference { attribute: "comfort".to_string(), weight: 0.7 },
    Preference { attribute: "firmness".to_string(), weight: 0.3 },
    Preference { attribute: "price".to_string(), weight: -0.5 }, // Strong price sensitivity
];

let best_bed = choose_bed(&beds, &preferences).unwrap();

println!("The best bed within your budget is: {:?}", best_bed);

}

3. Adding a New Bed Attribute (e.g., Material):

While the core crate focuses on numerical attributes, you can extend it by adding a preprocessing step to convert categorical attributes into numerical representations. For instance, you could map "Memory Foam" to a comfort score of 9, and "Spring" to a comfort score of 6. The following shows how you could add a "material" attribute and convert it to a numerical representation before using the choose_bed function. rust use choose_your_bed::{Bed, Preference, choose_bed};

#[derive(Debug)] struct ExtendedBed { comfort: i32, firmness: i32, price: f64, material: String, }

fn convert_to_bed(extended_bed: &ExtendedBed) -> Bed { let comfort_bonus = match extended_bed.material.as_str() { "Memory Foam" => 2, "Latex" => 1, _ => 0, };

Bed {
    comfort: extended_bed.comfort + comfort_bonus,
    firmness: extended_bed.firmness,
    price: extended_bed.price,
}

}

fn main() { let extended_beds = vec![ ExtendedBed { comfort: 7, firmness: 4, price: 400.0, material: "Memory Foam".to_string() }, ExtendedBed { comfort: 6, firmness: 6, price: 600.0, material: "Spring".to_string() }, ExtendedBed { comfort: 9, firmness: 3, price: 800.0, material: "Latex".to_string() }, ];

let beds: Vec<Bed> = extended_beds.iter().map(convert_to_bed).collect();

let preferences = vec![
    Preference { attribute: "comfort".to_string(), weight: 0.7 },
    Preference { attribute: "firmness".to_string(), weight: 0.3 },
    Preference { attribute: "price".to_string(), weight: -0.5 },
];

let best_bed = choose_bed(&beds, &preferences).unwrap();

println!("The best bed is: {:?}", best_bed);

}

4. Handling Empty Bed Lists: rust use choose_your_bed::{Bed, Preference, choose_bed};

fn main() { let beds: Vec = Vec::new(); // Empty list of beds

let preferences = vec![
    Preference { attribute: "comfort".to_string(), weight: 0.5 },
    Preference { attribute: "firmness".to_string(), weight: 0.5 },
];

let best_bed = choose_bed(&beds, &preferences);

match best_bed {
    Some(bed) => println!("The best bed is: {:?}", bed),
    None => println!("No beds available to choose from!"),
}

}

Features

  • Flexible Bed Definition: Define beds with customizable comfort, firmness, and price attributes.
  • Weighted Preferences: Specify user preferences with varying weights for each attribute.
  • Easy Integration: Simple API for seamless integration into your Rust projects.
  • Clear Error Handling: Provides Option return types to handle cases where no suitable bed can be found.
  • Extensible: Designed to be extended with custom bed attributes through preprocessing.

License

MIT

This crate is part of the choose-your-bed ecosystem. For advanced features and enterprise-grade tools, visit: https://supermaker.ai/blog/how-to-make-the-viral-choose-your-bed-videos-with-ai/

Commit count: 0

cargo fmt