Skip to content

Commit

Permalink
fix clippy stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
catornot committed Jan 19, 2024
1 parent fe13c9e commit 3f1252e
Show file tree
Hide file tree
Showing 23 changed files with 157 additions and 127 deletions.
6 changes: 3 additions & 3 deletions rrplug_proc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ pub fn as_interface(_attr: TokenStream, item: TokenStream) -> TokenStream {
#(#attrs)*
#vis #defaultness #sig {
use rrplug::interfaces::interface::AsInterface;
Self::as_interface({
Self::to_interface({
#(#stmts)*
})
}
Expand Down Expand Up @@ -568,14 +568,14 @@ pub fn as_interface(_attr: TokenStream, item: TokenStream) -> TokenStream {

#(#attrs)*
impl #generics rrplug::interfaces::interface::AsInterface for #self_ty {
fn as_interface(self) -> rrplug::interfaces::interface::Interface<Self> {
fn to_interface(self) -> rrplug::interfaces::interface::Interface<Self> {
// make these extern c wrapped and offset the self since it will have the vtable
// TODO: make generic functions work (big headache)
#(
#[allow(unsafe_op_in_unsafe_fn)]
unsafe extern "C" fn #function_idents #generics(self_: *const std::ffi::c_void, #extern_inputs) #extern_outputs {
// transmute because I want to be lazy here
#self_ty_ident::#generics_bracked #function_idents(std::mem::transmute(self_.offset(std::mem::size_of::<usize>() as isize)), #extern_inputs_idents )
#self_ty_ident::#generics_bracked #function_idents(self_.cast::<usize>().add(1).cast::<#self_ty_ident>().as_ref().expect("how!"), #extern_inputs_idents )
}
)*

Expand Down
5 changes: 3 additions & 2 deletions src/bindings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl<T, const U: usize> std::ops::DerefMut for OffsetStructField<T, U> {
}

impl<T, const U: usize> OffsetStructField<T, U> {
pub fn get_inner(&self) -> &T {
pub const fn get_inner(&self) -> &T {
&self.value
}

Expand All @@ -40,7 +40,8 @@ impl<T, const U: usize> OffsetStructField<T, U> {
}

impl<T: Copy + Clone, const U: usize> OffsetStructField<T, U> {
pub fn copy_inner(&self) -> T {
/// Returns the copy inner of this [`OffsetStructField<T, U>`].
pub const fn copy_inner(&self) -> T {
self.value
}
}
Expand Down
152 changes: 76 additions & 76 deletions src/bindings/squirrelfunctions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,88 +148,88 @@ pub struct SquirrelFunctions {
pub sq_sealstructslot: sq_sealstructslotType,
}

impl Into<SquirrelFunctions> for ClientSQFunctions {
fn into(self) -> SquirrelFunctions {
impl From<ClientSQFunctions> for SquirrelFunctions {
fn from(val: ClientSQFunctions) -> Self {
SquirrelFunctions {
register_squirrel_func: self.register_squirrel_func,
sq_defconst: self.sq_defconst,
sq_compilebuffer: self.sq_compilebuffer,
sq_call: self.sq_call,
sq_raiseerror: self.sq_raiseerror,
sq_compilefile: self.sq_compilefile,
sq_newarray: self.sq_newarray,
sq_arrayappend: self.sq_arrayappend,
sq_newtable: self.sq_newtable,
sq_newslot: self.sq_newslot,
sq_pushroottable: self.sq_pushroottable,
sq_pushstring: self.sq_pushstring,
sq_pushinteger: self.sq_pushinteger,
sq_pushfloat: self.sq_pushfloat,
sq_pushbool: self.sq_pushbool,
sq_pushasset: self.sq_pushasset,
sq_pushvector: self.sq_pushvector,
sq_pushobject: self.sq_pushobject,
sq_getstring: self.sq_getstring,
sq_getinteger: self.sq_getinteger,
sq_getfloat: self.sq_getfloat,
sq_getbool: self.sq_getbool,
sq_get: self.sq_get,
sq_getasset: self.sq_getasset,
sq_getuserdata: self.sq_getuserdata,
sq_getvector: self.sq_getvector,
sq_getthisentity: self.sq_getthisentity,
sq_getobject: self.sq_getobject,
sq_stackinfos: self.sq_stackinfos,
sq_createuserdata: self.sq_createuserdata,
sq_setuserdatatypeid: self.sq_setuserdatatypeid,
sq_getfunction: self.sq_getfunction,
sq_getentityfrominstance: self.sq_getentityfrominstance,
sq_get_entity_constant_cbase_entity: self.sq_get_entity_constant_cbase_entity,
sq_pushnewstructinstance: self.sq_pushnewstructinstance,
sq_sealstructslot: self.sq_sealstructslot,
register_squirrel_func: val.register_squirrel_func,
sq_defconst: val.sq_defconst,
sq_compilebuffer: val.sq_compilebuffer,
sq_call: val.sq_call,
sq_raiseerror: val.sq_raiseerror,
sq_compilefile: val.sq_compilefile,
sq_newarray: val.sq_newarray,
sq_arrayappend: val.sq_arrayappend,
sq_newtable: val.sq_newtable,
sq_newslot: val.sq_newslot,
sq_pushroottable: val.sq_pushroottable,
sq_pushstring: val.sq_pushstring,
sq_pushinteger: val.sq_pushinteger,
sq_pushfloat: val.sq_pushfloat,
sq_pushbool: val.sq_pushbool,
sq_pushasset: val.sq_pushasset,
sq_pushvector: val.sq_pushvector,
sq_pushobject: val.sq_pushobject,
sq_getstring: val.sq_getstring,
sq_getinteger: val.sq_getinteger,
sq_getfloat: val.sq_getfloat,
sq_getbool: val.sq_getbool,
sq_get: val.sq_get,
sq_getasset: val.sq_getasset,
sq_getuserdata: val.sq_getuserdata,
sq_getvector: val.sq_getvector,
sq_getthisentity: val.sq_getthisentity,
sq_getobject: val.sq_getobject,
sq_stackinfos: val.sq_stackinfos,
sq_createuserdata: val.sq_createuserdata,
sq_setuserdatatypeid: val.sq_setuserdatatypeid,
sq_getfunction: val.sq_getfunction,
sq_getentityfrominstance: val.sq_getentityfrominstance,
sq_get_entity_constant_cbase_entity: val.sq_get_entity_constant_cbase_entity,
sq_pushnewstructinstance: val.sq_pushnewstructinstance,
sq_sealstructslot: val.sq_sealstructslot,
}
}
}

impl Into<SquirrelFunctions> for ServerSQFunctions {
fn into(self) -> SquirrelFunctions {
impl From<ServerSQFunctions> for SquirrelFunctions {
fn from(val: ServerSQFunctions) -> Self {
SquirrelFunctions {
register_squirrel_func: self.register_squirrel_func,
sq_defconst: self.sq_defconst,
sq_compilebuffer: self.sq_compilebuffer,
sq_call: self.sq_call,
sq_raiseerror: self.sq_raiseerror,
sq_compilefile: self.sq_compilefile,
sq_newarray: self.sq_newarray,
sq_arrayappend: self.sq_arrayappend,
sq_newtable: self.sq_newtable,
sq_newslot: self.sq_newslot,
sq_pushroottable: self.sq_pushroottable,
sq_pushstring: self.sq_pushstring,
sq_pushinteger: self.sq_pushinteger,
sq_pushfloat: self.sq_pushfloat,
sq_pushbool: self.sq_pushbool,
sq_pushasset: self.sq_pushasset,
sq_pushvector: self.sq_pushvector,
sq_pushobject: self.sq_pushobject,
sq_getstring: self.sq_getstring,
sq_getinteger: self.sq_getinteger,
sq_getfloat: self.sq_getfloat,
sq_getbool: self.sq_getbool,
sq_get: self.sq_get,
sq_getasset: self.sq_getasset,
sq_getuserdata: self.sq_getuserdata,
sq_getvector: self.sq_getvector,
sq_getthisentity: self.sq_getthisentity,
sq_getobject: self.sq_getobject,
sq_stackinfos: self.sq_stackinfos,
sq_createuserdata: self.sq_createuserdata,
sq_setuserdatatypeid: self.sq_setuserdatatypeid,
sq_getfunction: self.sq_getfunction,
sq_getentityfrominstance: self.sq_getentityfrominstance,
sq_get_entity_constant_cbase_entity: self.sq_get_entity_constant_cbase_entity,
sq_pushnewstructinstance: self.sq_pushnewstructinstance,
sq_sealstructslot: self.sq_sealstructslot,
register_squirrel_func: val.register_squirrel_func,
sq_defconst: val.sq_defconst,
sq_compilebuffer: val.sq_compilebuffer,
sq_call: val.sq_call,
sq_raiseerror: val.sq_raiseerror,
sq_compilefile: val.sq_compilefile,
sq_newarray: val.sq_newarray,
sq_arrayappend: val.sq_arrayappend,
sq_newtable: val.sq_newtable,
sq_newslot: val.sq_newslot,
sq_pushroottable: val.sq_pushroottable,
sq_pushstring: val.sq_pushstring,
sq_pushinteger: val.sq_pushinteger,
sq_pushfloat: val.sq_pushfloat,
sq_pushbool: val.sq_pushbool,
sq_pushasset: val.sq_pushasset,
sq_pushvector: val.sq_pushvector,
sq_pushobject: val.sq_pushobject,
sq_getstring: val.sq_getstring,
sq_getinteger: val.sq_getinteger,
sq_getfloat: val.sq_getfloat,
sq_getbool: val.sq_getbool,
sq_get: val.sq_get,
sq_getasset: val.sq_getasset,
sq_getuserdata: val.sq_getuserdata,
sq_getvector: val.sq_getvector,
sq_getthisentity: val.sq_getthisentity,
sq_getobject: val.sq_getobject,
sq_stackinfos: val.sq_stackinfos,
sq_createuserdata: val.sq_createuserdata,
sq_setuserdatatypeid: val.sq_setuserdatatypeid,
sq_getfunction: val.sq_getfunction,
sq_getentityfrominstance: val.sq_getentityfrominstance,
sq_get_entity_constant_cbase_entity: val.sq_get_entity_constant_cbase_entity,
sq_pushnewstructinstance: val.sq_pushnewstructinstance,
sq_sealstructslot: val.sq_sealstructslot,
}
}
}
13 changes: 13 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,16 @@ impl CStringPtrError {
log::error!("{}", self)
}
}

#[derive(Error, Debug)]
pub enum CompletionError {
#[error("no more completion slots remain")]
NoCompletionSlotsLeft,
}

impl CompletionError {
/// logs the error with the builtin logger
pub fn log(&self) {
log::error!("{}", self)
}
}
2 changes: 1 addition & 1 deletion src/high/class_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl<T> Iterator for PointerIterator<T> {
impl<T> PointerIterator<T> {
/// # Safety
/// the pointer must be an array of pointers to `T` terminated by a null pointer
pub unsafe fn new(ptr: *mut T) -> Self {
pub const unsafe fn new(ptr: *mut T) -> Self {
Self { ptr }
}
}
7 changes: 4 additions & 3 deletions src/high/concommands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ use crate::{
bindings::cvar::command::{
CCommand, COMMAND_COMPLETION_ITEM_LENGTH, COMMAND_COMPLETION_MAXITEMS,
},
errors::CompletionError,
mid::utils::set_c_char_array,
};

Expand Down Expand Up @@ -122,9 +123,9 @@ impl<'a> From<*mut [c_char; COMMAND_COMPLETION_ITEM_LENGTH as usize]> for Comman
}
}
impl CommandCompletion<'_> {
pub fn push<'b>(&mut self, new: &'b str) -> Result<(), ()> {
pub fn push(&mut self, new: &str) -> Result<(), CompletionError> {
if self.suggestions_left == 0 {
return Err(());
return Err(CompletionError::NoCompletionSlotsLeft);
}

unsafe {
Expand All @@ -139,7 +140,7 @@ impl CommandCompletion<'_> {
Ok(())
}

pub fn commands_used(&self) -> i32 {
pub const fn commands_used(&self) -> i32 {
(COMMAND_COMPLETION_MAXITEMS - self.suggestions_left) as i32
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/high/convars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ impl ConVarStruct {
default_value_ptr.copy_from_nonoverlapping(default_value.as_ptr(), default_value.len())
};

let help_string = try_cstring(&register_info.help_string)?.into_bytes_with_nul();
let help_string = try_cstring(register_info.help_string)?.into_bytes_with_nul();
let help_string_ptr = unsafe { SOURCE_ALLOC.alloc(Layout::for_value(&help_string)) };
unsafe {
help_string_ptr.copy_from_nonoverlapping(help_string.as_ptr(), help_string.len())
Expand Down
14 changes: 11 additions & 3 deletions src/high/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,15 @@ impl EngineToken {
todo!()
}

pub unsafe fn new_unchecked() -> Self {
/// allows you to call engine restricted functions without checking if it's the right thread
///
/// # Safety
/// please only use this if you are sure that it is the engine thread
///
/// can lead to crashes or ub since most functions are not thread safe
///
/// this is usually the most sensible solution altought it does at least require you to think from where you call stuff
pub const unsafe fn new_unchecked() -> Self {
Self(PhantomData)
}
}
Expand All @@ -46,7 +54,7 @@ impl<T> EngineGlobal<T> {
Self(UnsafeHandle { inner: data })
}

pub fn get(&self, _: EngineToken) -> &T {
pub const fn get(&self, _: EngineToken) -> &T {
self.0.get()
}

Expand All @@ -60,7 +68,7 @@ impl<T> EngineGlobal<T> {
}

impl<T: Copy> EngineGlobal<T> {
pub fn copy(&self, _: EngineToken) -> T {
pub const fn copy(&self, _: EngineToken) -> T {
self.0.copy()
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/high/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ pub mod engine_sync;
pub mod engine_sync {
#[doc(hidden)]
#[inline(always)]
pub fn init_async_routine() {}
pub const fn init_async_routine() {}

#[doc(hidden)]
#[inline(always)]
pub unsafe fn run_async_routine() {}
pub const unsafe fn run_async_routine() {}
}

/// allows some tf2 types to be send and sync
Expand Down Expand Up @@ -51,7 +51,7 @@ impl<T> UnsafeHandle<T> {
}

/// returns a ref to the underlying value
pub fn get(&self) -> &T {
pub const fn get(&self) -> &T {
&self.inner
}

Expand All @@ -68,7 +68,7 @@ impl<T> UnsafeHandle<T> {

impl<T: Clone + Copy> UnsafeHandle<T> {
/// copies the underlying value if it has [`Copy`]
pub fn copy(&self) -> T {
pub const fn copy(&self) -> T {
self.inner
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/high/squirrel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ impl CSquirrelVMHandle {
/// [`UnsafeHandle`] : when used outside of engine thread can cause race conditions or ub
///
/// [`UnsafeHandle`] should only be used to transfer the pointers to other places in the engine thread like sqfunctions or runframe
pub unsafe fn get_cs_sqvm(&self) -> UnsafeHandle<*mut CSquirrelVM> {
pub const unsafe fn get_cs_sqvm(&self) -> UnsafeHandle<*mut CSquirrelVM> {
UnsafeHandle::internal_new(self.handle)
}

/// gets the type of the sqvm :D
pub fn get_context(&self) -> ScriptContext {
pub const fn get_context(&self) -> ScriptContext {
self.vm_type
}
}
Expand Down Expand Up @@ -136,15 +136,15 @@ impl<H: IsSQObject> SQHandle<H> {
/// # Safety
///
/// this breaks the type guarantees provided by this struct
pub unsafe fn new_unchecked(value: SQObject) -> Self {
pub const unsafe fn new_unchecked(value: SQObject) -> Self {
Self {
inner: value,
marker: PhantomData,
}
}

/// a getter
pub fn get(&self) -> &SQObject {
pub const fn get(&self) -> &SQObject {
&self.inner
}

Expand All @@ -154,7 +154,7 @@ impl<H: IsSQObject> SQHandle<H> {
}

/// consumes itself and returns the [`SQObject`]
pub fn take(self) -> SQObject {
pub const fn take(self) -> SQObject {
self.inner
}
}
Expand Down
Loading

0 comments on commit 3f1252e

Please sign in to comment.