Skip to content

Commit

Permalink
Fix repr on raw strings
Browse files Browse the repository at this point in the history
Rust 2024
  • Loading branch information
VirxEC committed Feb 20, 2025
1 parent 62be68e commit 0855d0a
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 73 deletions.
18 changes: 9 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "rlbot_flatbuffers"
version = "0.13.3"
edition = "2021"
version = "0.13.4"
edition = "2024"
description = "A Python module implemented in Rust for serializing and deserializing RLBot's flatbuffers"
repository = "https://github.com/VirxEC/rlbot_flatbuffers_py"
build = "codegen/main.rs"
Expand Down
18 changes: 9 additions & 9 deletions codegen/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,25 +144,25 @@ impl PythonBindType {

pub fn filename(&self) -> &str {
match self {
Self::Struct(gen) => gen.filename(),
Self::Enum(gen) => gen.filename(),
Self::Union(gen) => gen.filename(),
Self::Struct(bind) => bind.filename(),
Self::Enum(bind) => bind.filename(),
Self::Union(bind) => bind.filename(),
}
}

pub fn struct_name(&self) -> &str {
match self {
Self::Struct(gen) => gen.struct_name(),
Self::Enum(gen) => gen.struct_name(),
Self::Union(gen) => gen.struct_name(),
Self::Struct(bind) => bind.struct_name(),
Self::Enum(bind) => bind.struct_name(),
Self::Union(bind) => bind.struct_name(),
}
}

pub fn generate(&mut self, filepath: &Path) -> io::Result<()> {
match self {
Self::Struct(gen) => gen.generate(filepath),
Self::Enum(gen) => gen.generate(filepath),
Self::Union(gen) => gen.generate(filepath),
Self::Struct(bind) => bind.generate(filepath),
Self::Enum(bind) => bind.generate(filepath),
Self::Union(bind) => bind.generate(filepath),
}
}
}
Expand Down
32 changes: 16 additions & 16 deletions codegen/pyi.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
PythonBindType,
generator::Generator,
structs::{InnerOptionType, InnerVecType, RustType},
PythonBindType,
};
use std::{borrow::Cow, fs, io};

Expand Down Expand Up @@ -49,8 +49,8 @@ pub fn generator(type_data: &[PythonBindType]) -> io::Result<()> {
write_fmt!(file, "class {type_name}:");

match item {
PythonBindType::Union(gen) => {
let types = gen
PythonBindType::Union(bind) => {
let types = bind
.types
.iter()
.map(|variable_info| variable_info.name.as_str())
Expand All @@ -68,8 +68,8 @@ pub fn generator(type_data: &[PythonBindType]) -> io::Result<()> {
write_fmt!(file, " self, item: {union_str} = {default_value}()");
write_str!(file, " ): ...\n");
}
PythonBindType::Enum(gen) => {
for variable_info in &gen.types {
PythonBindType::Enum(bind) => {
for variable_info in &bind.types {
let variable_name = variable_info.name.as_str();
if variable_name == "NONE" {
continue;
Expand Down Expand Up @@ -105,8 +105,8 @@ pub fn generator(type_data: &[PythonBindType]) -> io::Result<()> {
);
write_str!(file, " def __hash__(self) -> str: ...");
}
PythonBindType::Struct(gen) => {
if let Some(docs) = gen.struct_doc_str.as_ref() {
PythonBindType::Struct(bind) => {
if let Some(docs) = bind.struct_doc_str.as_ref() {
write_str!(file, " \"\"\"");

for line in docs {
Expand All @@ -118,7 +118,7 @@ pub fn generator(type_data: &[PythonBindType]) -> io::Result<()> {

let mut python_types = Vec::new();

'outer: for variable_info in &gen.types {
'outer: for variable_info in &bind.types {
let variable_name = variable_info.name.as_str();
let variable_type = variable_info.raw_type.as_str();

Expand Down Expand Up @@ -215,11 +215,11 @@ pub fn generator(type_data: &[PythonBindType]) -> io::Result<()> {
let union_types = type_data
.iter()
.find_map(|item| match item {
PythonBindType::Union(gen)
if gen.struct_name() == type_name =>
PythonBindType::Union(bind)
if bind.struct_name() == type_name =>
{
Some(
gen.types
bind.types
.iter()
.skip(1)
.map(|v| v.name.as_str())
Expand Down Expand Up @@ -250,17 +250,17 @@ pub fn generator(type_data: &[PythonBindType]) -> io::Result<()> {
}
}

if !gen.types.is_empty() {
if !bind.types.is_empty() {
write_str!(file, "");
write_str!(file, " __match_args__ = (");

for variable_info in &gen.types {
for variable_info in &bind.types {
write_fmt!(file, " \"{}\",", variable_info.name);
}
write_str!(file, " )");
}

if gen.types.is_empty() {
if bind.types.is_empty() {
write_str!(file, " def __init__(self): ...");
} else {
write_str!(file, "");
Expand All @@ -271,7 +271,7 @@ pub fn generator(type_data: &[PythonBindType]) -> io::Result<()> {
write_fmt!(file, " def __{func}__(");
write_fmt!(file, " {first_arg},");

for (variable_info, python_type) in gen.types.iter().zip(&python_types) {
for (variable_info, python_type) in bind.types.iter().zip(&python_types) {
let variable_name = variable_info.name.as_str();

let default_value = match variable_info.raw_type.as_str() {
Expand Down Expand Up @@ -315,7 +315,7 @@ pub fn generator(type_data: &[PythonBindType]) -> io::Result<()> {
write_str!(file, " Serializes this instance into a byte array");
write_str!(file, " \"\"\"");

if !gen.is_frozen {
if !bind.is_frozen {
write_str!(file, " def unpack_with(self, data: bytes):");
write_str!(file, " \"\"\"");
write_str!(file, " Deserializes the data into this instance\n");
Expand Down
Loading

0 comments on commit 0855d0a

Please sign in to comment.