Crates.io | lyrical-meter |
lib.rs | lyrical-meter |
version | 0.1.0 |
source | src |
created_at | 2024-11-09 17:52:36.520507 |
updated_at | 2024-11-09 17:52:36.520507 |
description | A Rust crate for representing and working with various poetic meters. |
homepage | https://github.com/klebs6/klebs-general |
repository | https://github.com/klebs6/klebs-general |
max_upload_size | |
id | 1442268 |
size | 36,214 |
A Rust crate for representing and working with various poetic meters. Ideal for applications in poetry generation, analysis, and education.
serde
.Clone
, Copy
, Debug
, PartialEq
, and Eq
.Add the following to your Cargo.toml
:
[dependencies]
lyrical-meter = "0.1.0"
Then, in your Rust code:
extern crate lyrical_meter;
use lyrical_meter::{Meter, LyricalMeter, MetricalFoot, LineLength};
fn main() {
let meter = Meter::Standard(
LyricalMeter::builder()
.foot(MetricalFoot::Iamb)
.length(LineLength::Pentameter)
.build(),
);
println!("Meter: {}", meter);
println!("AI Description: {}", meter.ai());
}
Output:
Meter: Iamb in Pentameter
AI Description: Use iambic meter, with unstressed-stressed syllables. Each line should have five feet (pentameter).
use lyrical_meter::{Meter, OtherMeter};
fn main() {
let meter = Meter::Other(OtherMeter::FreeVerse);
println!("Meter: {}", meter);
println!("AI Description: {}", meter.ai());
}
Output:
Meter: Write in free verse, without a consistent meter or rhyme scheme.
AI Description: Write in free verse, without a consistent meter or rhyme scheme.
use lyrical_meter::Meter;
use rand::Rng;
fn main() {
let mut rng = rand::thread_rng();
let random_meter: Meter = rng.gen();
println!("Random Meter: {}", random_meter);
println!("AI Description: {}", random_meter.ai());
}
use lyrical_meter::{Meter, OtherMeter};
use serde_json;
fn main() {
let meter = Meter::Other(OtherMeter::BlankVerse);
let serialized = serde_json::to_string(&meter).unwrap();
let deserialized: Meter = serde_json::from_str(&serialized).unwrap();
assert_eq!(meter, deserialized);
println!("Serialized Meter: {}", serialized);
}
Output:
Serialized Meter: {"Other":"BlankVerse"}
use lyrical_meter::{Meter, LyricalMeter, MetricalFoot, LineLength};
fn main() {
// Using the builder pattern
let mut lyrical_meter = LyricalMeter::builder()
.foot(MetricalFoot::Trochee)
.length(LineLength::Tetrameter)
.build();
// Modifying using setters
lyrical_meter.set_foot(MetricalFoot::Anapest);
lyrical_meter.set_length(Some(LineLength::Trimeter));
println!("Modified Meter: {}", lyrical_meter);
}
Output:
Modified Meter: Anapest in Trimeter
For more detailed information, please refer to the documentation.
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
Inspired by the need for a robust and flexible representation of poetic meters in Rust applications.