Added documentation
[?]
8LW8624xwrzheYNE1i3XKqUsNUezeTo6cRFa6qrKJout
Oct 11, 2021, 9:50 AM
RXIJUOA6ZV5WLAXOEMPFCOGYCCJSN5N76TFCMPVHRHC4S4G2CFHACDependencies
- [2]
SCXWTGGEfeature regex - [3]
6ON2OTNRinit - [4]
BK53SCKObasic implementation for EmoteMapper - [5]
22DV2RSXAdd example for Twitchemotes
Change contents
- edit in src/lib.rs at line 1
#![warn(missing_docs)]//! # Emote Mapper//!//! `emote_mapper` is a collection of utilities to create and use emote maps from [`twitchmote`](https://github.com/ModProg/twitchmote) - edit in src/lib.rs at line 20
use serde::*;use serde_with::{serde_as, TryFromInto};use thiserror::Error; - replacement in src/lib.rs at line 24
use serde::*;use serde_with::{serde_as, TryFromInto};use thiserror::Error; - edit in src/lib.rs at line 29
/// The EmoteMapper holds a Map of emote names and code points/// It can be used for:/// - using an emote map stored as csv to map emotes/// - storing an emote map as csv - replacement in src/lib.rs at line 39
fn default() -> Self {Self {map: Default::default(),emote_width: 3,}}fn default() -> Self { Self { map: Default::default(), emote_width: 3 } } - edit in src/lib.rs at line 43
/// The emote width used for `to_string` and `replace_all`////// **NOTE:** This depends both on the emote and the primary font used by the terminal - replacement in src/lib.rs at line 51
pub fn to_char(&self, emote_name: &str) -> Option<char> {self.map.get(emote_name).copied().map(char::from)}/// Returns the char representing the `emote_name`pub fn to_char(&self, emote_name: &str) -> Option<char> { self.map.get(emote_name).copied().map(char::from) } - edit in src/lib.rs at line 54
/// Returns a string with the char representing the `emote_name` padded to `emte_width` - replacement in src/lib.rs at line 56
self.to_char(emote_name).map(|c| format!("{}{}", c, " ".repeat(self.emote_width - 1)))self.to_char(emote_name).map(|c| format!("{}{}", c, " ".repeat(self.emote_width - 1))) - edit in src/lib.rs at line 59
/// Replaces all emotes in the `message` given - replacement in src/lib.rs at line 67
self.to_string(w.get(0).unwrap().as_str()).unwrap_or_else(|| w.get(0).unwrap().as_str().to_owned())self.to_string(w.get(0).unwrap().as_str()).unwrap_or_else(|| w.get(0).unwrap().as_str().to_owned()) - edit in src/lib.rs at line 74
/// Creates an EmoteMapper from a Reader containing csv data - replacement in src/lib.rs at line 76
let mut rdr = csv::ReaderBuilder::new().has_headers(false).trim(Trim::All).from_reader(rdr);let mut rdr = csv::ReaderBuilder::new().has_headers(false).trim(Trim::All).from_reader(rdr); - replacement in src/lib.rs at line 85
Ok(EmoteMapper {map,..EmoteMapper::default()})Ok(EmoteMapper { map, ..EmoteMapper::default() }) - replacement in src/lib.rs at line 87
pub fn from_path(p: &Path) -> Result<Self, EmoteMapperError> {Self::from_reader(File::open(p).map_err(IOError)?)}/// Creates an EmoteMapper from a File containing csv datapub fn from_path(p: &Path) -> Result<Self, EmoteMapperError> { Self::from_reader(File::open(p).map_err(IOError)?) } - replacement in src/lib.rs at line 95
fn from_str(s: &str) -> Result<Self, Self::Err> {Self::from_reader(s.as_bytes())}/// Creates an EmoteMapper from a String containing csv datafn from_str(s: &str) -> Result<Self, Self::Err> { Self::from_reader(s.as_bytes()) } - edit in src/lib.rs at line 101
/// Writes the EmoteMapper as csv to a Writer - replacement in src/lib.rs at line 103
let mut wtr = csv::WriterBuilder::new().has_headers(false).from_writer(wtr);let mut wtr = csv::WriterBuilder::new().has_headers(false).from_writer(wtr); - edit in src/lib.rs at line 108
}pub fn to_path(self, p: &Path) -> Result<(), EmoteMapperError> {self.to_writer(File::open(p).map_err(IOError)?) - edit in src/lib.rs at line 109
/// Stores the EmoteMapper as csv in a Filepub fn to_path(self, p: &Path) -> Result<(), EmoteMapperError> { self.to_writer(File::open(p).map_err(IOError)?) } - edit in src/lib.rs at line 115
/// The EmoteMapper as CSV - replacement in src/lib.rs at line 119
val.to_writer(unsafe { s.as_mut_vec() }).expect("Writing to String should not fail");val.to_writer(unsafe { s.as_mut_vec() }).expect("Writing to String should not fail"); - replacement in src/lib.rs at line 142
fn from((name, code_point): (String, CodePoint)) -> Self {Mapping { name, code_point }}fn from((name, code_point): (String, CodePoint)) -> Self { Mapping { name, code_point } } - edit in src/lib.rs at line 146
#[allow(missing_docs)] - replacement in src/lib.rs at line 160
fn from(cp: CodePoint) -> Self {cp.0}fn from(cp: CodePoint) -> Self { cp.0 } - replacement in src/lib.rs at line 164
fn fmt(&self, f: &mut __private::Formatter<'_>) -> std::fmt::Result {char::from(*self).fmt(f)}fn fmt(&self, f: &mut __private::Formatter<'_>) -> std::fmt::Result { char::from(*self).fmt(f) } - replacement in src/lib.rs at line 168
fn from(val: CodePoint) -> Self {format!("{:X}", val.0 as u32)}fn from(val: CodePoint) -> Self { format!("{:X}", val.0 as u32) } - replacement in src/lib.rs at line 176
char::from_u32(u32::from_str_radix(&s, 16).map_err(|_| InvalidCodepoint(s.to_string()))?,).ok_or_else(|| InvalidCodepoint(s.to_string()))?,char::from_u32(u32::from_str_radix(&s, 16).map_err(|_| InvalidCodepoint(s.to_string()))?).ok_or_else(|| InvalidCodepoint(s.to_string()))?, - replacement in examples/twitchchat.rs at line 6
let em = EmoteMapper::from_path(&PathBuf::from("examples/twitch_emotes.csv")).unwrap().emote_width(2);let em = EmoteMapper::from_path(&PathBuf::from("examples/twitch_emotes.csv")).unwrap().emote_width(2); - replacement in examples/twitchchat.rs at line 8
let messages = vec!["modproHi, how are you doing?","<3, great","tggleBoss Kappa xD",];let messages = vec!["modproHi, how are you doing?", "<3, great", "tggleBoss Kappa xD"];