Skip to content

Commit 8604076

Browse files
committed
Format.
1 parent a4fcd95 commit 8604076

File tree

17 files changed

+118
-136
lines changed

17 files changed

+118
-136
lines changed

.rustfmt.toml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
1-
imports_granularity = "Crate"
1+
fn_args_layout = "Compressed"
2+
format_code_in_doc_comments = true
3+
format_macro_bodies = true
4+
format_macro_matchers = true
5+
format_strings = true
6+
imports_granularity = "Crate"
7+
merge_derives = true
8+
newline_style = "Unix"
9+
normalize_comments = true
10+
reorder_impl_items = true
11+
use_field_init_shorthand = true
12+
wrap_comments = true

examples/http-client/src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::mem::{take, replace};
1+
use std::mem::{replace, take};
22

33
pub fn replace_and_set<T: Default>(t: &mut T, f: impl FnOnce(T) -> T) {
44
let x = f(take(t));

phper-alloc/src/lib.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ use std::{
1212

1313
/// The item which can be placed into container [EBox].
1414
pub trait EAllocatable {
15-
/// The method to free the heap allocated by `emalloc`, should call `efree` at the end.
16-
///
15+
/// The method to free the heap allocated by `emalloc`, should call `efree`
16+
/// at the end.
17+
///
1718
/// # Safety
1819
unsafe fn free(ptr: *mut Self) {
1920
_efree(ptr.cast());
@@ -22,7 +23,8 @@ pub trait EAllocatable {
2223

2324
/// The Box which use php `emalloc` and `efree` to manage memory.
2425
///
25-
/// TODO now feature `allocator_api` is still unstable, implement myself, use Box<T, Alloc> later.
26+
/// TODO now feature `allocator_api` is still unstable, implement myself, use
27+
/// Box<T, Alloc> later.
2628
pub struct EBox<T: EAllocatable> {
2729
ptr: *mut T,
2830
}
@@ -43,9 +45,9 @@ impl<T: EAllocatable> EBox<T> {
4345
}
4446

4547
/// Constructs from a raw pointer.
46-
///
48+
///
4749
/// # Safety
48-
///
50+
///
4951
/// Make sure the pointer is created from `emalloc`.
5052
pub unsafe fn from_raw(raw: *mut T) -> Self {
5153
Self { ptr: raw }

phper-macros/src/derives.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ fn parse_throwable_attrs(input: &DeriveInput) -> syn::Result<TokenStream2> {
2222
}
2323

2424
fn parse_throwable_input(
25-
input: &DeriveInput,
26-
crate_ident: TokenStream2,
27-
exception: TokenStream2,
25+
input: &DeriveInput, crate_ident: TokenStream2, exception: TokenStream2,
2826
) -> syn::Result<TokenStream> {
2927
let input_ident = &input.ident;
3028

@@ -49,7 +47,8 @@ fn parse_throwable_input(
4947
_ => {
5048
return Err(syn::Error::new_spanned(
5149
&variant,
52-
"now only support unnamed field with one item mark attribute #[throwable]",
50+
"now only support unnamed field with one item mark attribute \
51+
#[throwable]",
5352
));
5453
}
5554
}

phper-macros/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#![warn(rust_2018_idioms, clippy::dbg_macro, clippy::print_stdout)]
22
#![doc = include_str!("../README.md")]
33

4-
// TODO Write a bridge macro for easy usage about register functions and classes, like `cxx`.
4+
// TODO Write a bridge macro for easy usage about register functions and
5+
// classes, like `cxx`.
56

67
mod alloc;
78
mod derives;
@@ -60,7 +61,6 @@ pub fn c_str_ptr(input: TokenStream) -> TokenStream {
6061
///
6162
/// module
6263
/// }
63-
///
6464
/// ```
6565
#[proc_macro_attribute]
6666
pub fn php_get_module(attr: TokenStream, input: TokenStream) -> TokenStream {
@@ -84,7 +84,8 @@ pub fn php_get_module(attr: TokenStream, input: TokenStream) -> TokenStream {
8484
/// }
8585
/// ```
8686
///
87-
/// TODO Support attribute `throwable` with `class`, `code` and `message`, integration tests.
87+
/// TODO Support attribute `throwable` with `class`, `code` and `message`,
88+
/// integration tests.
8889
#[proc_macro_derive(Throwable, attributes(throwable, throwable_class))]
8990
pub fn derive_throwable(input: TokenStream) -> TokenStream {
9091
let input = parse_macro_input!(input as DeriveInput);

phper-test/src/cli.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ use std::{
88

99
use crate::{context::Context, utils};
1010

11-
/// Check your extension by executing the php script, if the all executing return success, than the test is pass.
11+
/// Check your extension by executing the php script, if the all executing
12+
/// return success, than the test is pass.
1213
///
13-
/// - `exec_path` is the path of the make executable, which will be used to detect the path of
14+
/// - `exec_path` is the path of the make executable, which will be used to
15+
/// detect the path of
1416
/// extension lib.
1517
///
1618
/// - `scripts` is the path of your php test scripts.
@@ -28,17 +30,19 @@ pub fn test_php_scripts(exe_path: impl AsRef<Path>, scripts: &[&dyn AsRef<Path>]
2830
/// Script and condition pair.
2931
pub type ScriptCondition<'a> = (&'a dyn AsRef<Path>, &'a dyn Fn(Output) -> bool);
3032

31-
/// Check your extension by executing the php script, if the all your specified checkers are pass, than the test is pass.
33+
/// Check your extension by executing the php script, if the all your specified
34+
/// checkers are pass, than the test is pass.
3235
///
33-
/// - `exec_path` is the path of the make executable, which will be used to detect the path of
36+
/// - `exec_path` is the path of the make executable, which will be used to
37+
/// detect the path of
3438
/// extension lib.
3539
///
36-
/// - `scripts` is the slice of the tuple, format is `(path of your php test script, checker function or closure)`.
40+
/// - `scripts` is the slice of the tuple, format is `(path of your php test
41+
/// script, checker function or closure)`.
3742
///
3843
/// See [example logging integration test](https://github.com/jmjoy/phper/blob/master/examples/logging/tests/integration.rs).
3944
pub fn test_php_scripts_with_condition(
40-
exe_path: impl AsRef<Path>,
41-
scripts: &[ScriptCondition<'_>],
45+
exe_path: impl AsRef<Path>, scripts: &[ScriptCondition<'_>],
4246
) {
4347
let context = Context::get_global();
4448
let lib_path = utils::get_lib_path(exe_path);
@@ -82,11 +86,10 @@ pub fn test_php_scripts_with_condition(
8286
}
8387
}
8488

85-
/// Check your extension by executing the long term php script such as http server, if the all your
86-
/// specified checkers are pass, than the test is pass.
89+
/// Check your extension by executing the long term php script such as http
90+
/// server, if the all your specified checkers are pass, than the test is pass.
8791
pub fn test_long_term_php_script_with_condition(
88-
exe_path: impl AsRef<Path>,
89-
script: impl AsRef<Path>,
92+
exe_path: impl AsRef<Path>, script: impl AsRef<Path>,
9093
condition: impl FnOnce(&Child) + UnwindSafe,
9194
) {
9295
let context = Context::get_global();

phper-test/src/context.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ impl Context {
7373
}
7474

7575
pub fn create_command_with_tmp_php_ini_args(
76-
&self,
77-
tmp_php_ini_file: &NamedTempFile,
78-
script: impl AsRef<Path>,
76+
&self, tmp_php_ini_file: &NamedTempFile, script: impl AsRef<Path>,
7977
) -> ContextCommand {
8078
let mut cmd = Command::new(&self.php_bin);
8179
let args = vec![

phper-test/src/fpm.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//! Test tools for php fpm program.
2-
//!
32
use crate::{context::Context, utils, utils::spawn_command};
43
use fastcgi_client::{Client, Params, Request};
54
use libc::{atexit, kill, pid_t, SIGTERM};
@@ -92,10 +91,7 @@ extern "C" fn teardown() {
9291

9392
/// Start php-fpm and test the url request.
9493
pub fn test_fpm_request(
95-
method: &str,
96-
root: impl AsRef<Path>,
97-
request_uri: &str,
98-
content_type: Option<String>,
94+
method: &str, root: impl AsRef<Path>, request_uri: &str, content_type: Option<String>,
9995
body: Option<Vec<u8>>,
10096
) {
10197
assert!(FPM_HANDLE.get().is_some(), "must call `setup()` first");

phper/src/arrays.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,19 @@ impl Array {
4545
}
4646

4747
/// New Array reference from raw pointer.
48-
///
48+
///
4949
/// # Safety
50-
///
50+
///
5151
/// Make sure pointer is the type of `zend_array'.
5252
pub unsafe fn from_ptr<'a>(ptr: *const zend_array) -> Option<&'a Array> {
5353
let ptr = ptr as *const Array;
5454
ptr.as_ref()
5555
}
5656

5757
/// New Array mutable reference from raw pointer.
58-
///
58+
///
5959
/// # Safety
60-
///
60+
///
6161
/// Make sure pointer is the type of `zend_array'.
6262
pub unsafe fn from_mut_ptr<'a>(ptr: *mut zend_array) -> Option<&'a mut Array> {
6363
let ptr = ptr as *mut Array;
@@ -190,10 +190,10 @@ impl Array {
190190

191191
impl EAllocatable for Array {
192192
unsafe fn free(ptr: *mut Self) {
193-
(*ptr).inner.gc.refcount -= 1;
194-
if (*ptr).inner.gc.refcount == 0 {
195-
zend_array_destroy(ptr.cast());
196-
}
193+
(*ptr).inner.gc.refcount -= 1;
194+
if (*ptr).inner.gc.refcount == 0 {
195+
zend_array_destroy(ptr.cast());
196+
}
197197
}
198198
}
199199

phper/src/classes.rs

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ impl<T: Default + Send + 'static> DynamicClass<T> {
6060

6161
impl<T: Send + 'static> DynamicClass<T> {
6262
pub fn new_with_constructor(
63-
class_name: impl ToString,
64-
state_constructor: impl Fn() -> T + Send + Sync + 'static,
63+
class_name: impl ToString, state_constructor: impl Fn() -> T + Send + Sync + 'static,
6564
) -> Self {
6665
Self {
6766
class_name: class_name.to_string(),
@@ -72,15 +71,12 @@ impl<T: Send + 'static> DynamicClass<T> {
7271
_p: Default::default(),
7372
}
7473
// let ptr = &dyn_class.data_constructor as *const _ as usize;
75-
// dyn_class.add_property(DATA_CONSTRUCTOR_PROPERTY_NAME, ptr.to_string());
74+
// dyn_class.add_property(DATA_CONSTRUCTOR_PROPERTY_NAME,
75+
// ptr.to_string());
7676
}
7777

7878
pub fn add_method<F, R>(
79-
&mut self,
80-
name: impl ToString,
81-
vis: Visibility,
82-
handler: F,
83-
arguments: Vec<Argument>,
79+
&mut self, name: impl ToString, vis: Visibility, handler: F, arguments: Vec<Argument>,
8480
) where
8581
F: Fn(&mut Object<T>, &mut [Val]) -> R + Send + Sync + 'static,
8682
R: SetVal + 'static,
@@ -95,11 +91,7 @@ impl<T: Send + 'static> DynamicClass<T> {
9591
}
9692

9793
pub fn add_static_method<F, R>(
98-
&mut self,
99-
name: impl ToString,
100-
vis: Visibility,
101-
handler: F,
102-
arguments: Vec<Argument>,
94+
&mut self, name: impl ToString, vis: Visibility, handler: F, arguments: Vec<Argument>,
10395
) where
10496
F: Fn(&mut [Val]) -> R + Send + Sync + 'static,
10597
R: SetVal + 'static,
@@ -115,13 +107,11 @@ impl<T: Send + 'static> DynamicClass<T> {
115107

116108
/// Declare property.
117109
///
118-
/// The argument `value` should be `Copy` because 'zend_declare_property' receive only scalar
119-
/// zval , otherwise will report fatal error: "Internal zvals cannot be refcounted".
110+
/// The argument `value` should be `Copy` because 'zend_declare_property'
111+
/// receive only scalar zval , otherwise will report fatal error:
112+
/// "Internal zvals cannot be refcounted".
120113
pub fn add_property(
121-
&mut self,
122-
name: impl ToString,
123-
visibility: Visibility,
124-
value: impl Into<Scalar>,
114+
&mut self, name: impl ToString, visibility: Visibility, value: impl Into<Scalar>,
125115
) {
126116
self.property_entities
127117
.push(PropertyEntity::new(name, visibility, value));
@@ -168,11 +158,13 @@ pub type StatelessClassEntry = ClassEntry<()>;
168158
///
169159
/// # Generic
170160
///
171-
/// 1. Any `zend_class_entry` can be make into `ClassEntry<()>`, alias as [StatelessClassEntry].
161+
/// 1. Any `zend_class_entry` can be make into `ClassEntry<()>`, alias as
162+
/// [StatelessClassEntry].
172163
///
173-
/// 2. Only the `zend_class_entry` created by [crate::modules::Module::add_class] can be make into
174-
/// `ClassEntry<T>`, where `T` is the type defined by [Classifiable::state_type_id], as the inner
175-
/// state of `ClassEntry<T>` and `Object<T>`.
164+
/// 2. Only the `zend_class_entry` created by
165+
/// [crate::modules::Module::add_class] can be make into `ClassEntry<T>`, where
166+
/// `T` is the type defined by [Classifiable::state_type_id], as the inner state
167+
/// of `ClassEntry<T>` and `Object<T>`.
176168
#[repr(transparent)]
177169
pub struct ClassEntry<T: 'static> {
178170
inner: zend_class_entry,
@@ -226,8 +218,8 @@ impl<T: 'static> ClassEntry<T> {
226218
Ok(object)
227219
}
228220

229-
/// Create the object from class, without calling `__construct`, be careful when `__construct`
230-
/// is necessary.
221+
/// Create the object from class, without calling `__construct`, be careful
222+
/// when `__construct` is necessary.
231223
pub fn init_object(&self) -> crate::Result<EBox<Object<T>>> {
232224
unsafe {
233225
let ptr = self.as_ptr() as *mut _;

0 commit comments

Comments
 (0)