aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-php-shim
diff options
context:
space:
mode:
Diffstat (limited to 'crates/shirabe-php-shim')
-rw-r--r--crates/shirabe-php-shim/src/fs.rs6
-rw-r--r--crates/shirabe-php-shim/src/process.rs2
-rw-r--r--crates/shirabe-php-shim/src/stream.rs3
-rw-r--r--crates/shirabe-php-shim/src/xml.rs11
4 files changed, 8 insertions, 14 deletions
diff --git a/crates/shirabe-php-shim/src/fs.rs b/crates/shirabe-php-shim/src/fs.rs
index ba6eef6..e58623a 100644
--- a/crates/shirabe-php-shim/src/fs.rs
+++ b/crates/shirabe-php-shim/src/fs.rs
@@ -4,6 +4,7 @@ use crate::StreamBacking;
use crate::StreamState;
use crate::UnexpectedValueException;
use indexmap::IndexMap;
+use std::io::{Read as _, Write as _};
pub const PHP_EOL: &str = "\n";
@@ -329,7 +330,6 @@ pub fn fopen(file: &str, mode: &str) -> Result<PhpResource, std::io::Error> {
/// PHP `fwrite()`. `length` caps the number of bytes written (`None` = whole string).
/// Returns the byte count written, or `None` for PHP's `false`-on-failure.
pub fn fwrite(stream: &PhpResource, data: &str, length: Option<i64>) -> Option<i64> {
- use std::io::Write;
let bytes = data.as_bytes();
let bytes = match length {
Some(l) if l >= 0 => &bytes[..(l as usize).min(bytes.len())],
@@ -360,7 +360,6 @@ pub fn fwrite(stream: &PhpResource, data: &str, length: Option<i64>) -> Option<i
/// TODO(phase-e): byte-string semantics — should return Vec<u8>; from_utf8_lossy can corrupt
/// binary reads (filesAreEqual / binary copy).
pub fn fread(stream: &PhpResource, length: i64) -> Option<String> {
- use std::io::Read;
let cap = length.max(0) as usize;
match stream {
PhpResource::Stdin => {
@@ -482,7 +481,6 @@ fn fgets_read_line<R: std::io::Read + ?Sized>(
/// PHP `fgetc()`: reads a single byte, or `None` at end-of-stream.
/// TODO(phase-e): byte-string semantics — should return Vec<u8>.
pub fn fgetc(stream: &PhpResource) -> Option<String> {
- use std::io::Read;
let mut byte = [0u8; 1];
match stream {
PhpResource::Stdin => {
@@ -638,7 +636,6 @@ fn build_stat_map(size: u64, file_meta: Option<&std::fs::Metadata>) -> IndexMap<
/// PHP `fflush()`.
pub fn fflush(stream: &PhpResource) -> bool {
- use std::io::Write;
match stream {
PhpResource::Stdin => true,
PhpResource::Stdout => std::io::stdout().flush().is_ok(),
@@ -848,7 +845,6 @@ pub fn file_put_contents(_path: &str, _data: &[u8]) -> Option<i64> {
}
pub fn file_put_contents3(_filename: &str, _data: &str, _flags: i64) -> Option<i64> {
- use std::io::Write;
// TODO(phase-d): the LOCK_EX and FILE_USE_INCLUDE_PATH flags are ignored; only FILE_APPEND is
// honored.
let append = _flags & FILE_APPEND != 0;
diff --git a/crates/shirabe-php-shim/src/process.rs b/crates/shirabe-php-shim/src/process.rs
index ad6e1d5..901d345 100644
--- a/crates/shirabe-php-shim/src/process.rs
+++ b/crates/shirabe-php-shim/src/process.rs
@@ -52,7 +52,7 @@ pub fn shell_exec(command: &str) -> Option<String> {
}
pub fn system(command: &str, result_code: Option<&mut i64>) -> Option<String> {
- use std::io::Write;
+ use std::io::Write as _;
let result = std::process::Command::new("/bin/sh")
.arg("-c")
.arg(command)
diff --git a/crates/shirabe-php-shim/src/stream.rs b/crates/shirabe-php-shim/src/stream.rs
index 98f0322..ce6048c 100644
--- a/crates/shirabe-php-shim/src/stream.rs
+++ b/crates/shirabe-php-shim/src/stream.rs
@@ -1,5 +1,6 @@
use crate::{PhpMixed, PhpResource, StreamBacking};
use indexmap::IndexMap;
+use std::io::{Read as _, Write as _};
pub const STREAM_NOTIFY_FAILURE: i64 = 9;
pub const STREAM_NOTIFY_FILE_SIZE_IS: i64 = 5;
@@ -30,7 +31,6 @@ pub fn stream_get_contents_with_max(
// Reads from the stream's current position: all remaining bytes, or up to `max_length` when given
// (a negative max means "until end").
fn stream_read_remaining(stream: &PhpResource, max_length: Option<i64>) -> Option<String> {
- use std::io::Read;
match stream {
PhpResource::Stdin => {
let mut buf = Vec::new();
@@ -139,7 +139,6 @@ pub fn stream_get_wrappers() -> Vec<String> {
/// PHP `stream_copy_to_stream()`: copy the remaining bytes of `source` into `dest`, returning the
/// number of bytes copied (or `None` for `false`-on-failure).
pub fn stream_copy_to_stream(source: &PhpResource, dest: &PhpResource) -> Option<i64> {
- use std::io::{Read, Write};
let mut buf = Vec::new();
match source {
PhpResource::Stdin => {
diff --git a/crates/shirabe-php-shim/src/xml.rs b/crates/shirabe-php-shim/src/xml.rs
index cc323ca..b3938da 100644
--- a/crates/shirabe-php-shim/src/xml.rs
+++ b/crates/shirabe-php-shim/src/xml.rs
@@ -5,7 +5,6 @@
//! handles over that graph.
use std::cell::RefCell;
-use std::io::Write;
use std::rc::{Rc, Weak};
#[derive(Debug, Clone, Copy, PartialEq)]
@@ -120,7 +119,7 @@ impl DOMDocument {
self.0.borrow_mut().format_output = value;
}
- pub fn save_xml<W: Write>(&self, writer: &mut W) -> std::io::Result<()> {
+ pub fn save_xml<W: std::io::Write>(&self, writer: &mut W) -> std::io::Result<()> {
let doc = self.0.borrow();
writeln!(
writer,
@@ -250,7 +249,7 @@ fn collect_by_tag(
}
}
-fn serialize_node<W: Write>(
+fn serialize_node<W: std::io::Write>(
node: &Rc<RefCell<NodeInner>>,
depth: usize,
format: bool,
@@ -305,14 +304,14 @@ fn serialize_node<W: Write>(
Ok(())
}
-fn write_indent<W: Write>(out: &mut W, depth: usize) -> std::io::Result<()> {
+fn write_indent<W: std::io::Write>(out: &mut W, depth: usize) -> std::io::Result<()> {
for _ in 0..depth {
out.write_all(b" ")?;
}
Ok(())
}
-fn escape_text<W: Write>(s: &str, out: &mut W) -> std::io::Result<()> {
+fn escape_text<W: std::io::Write>(s: &str, out: &mut W) -> std::io::Result<()> {
let mut buf = [0u8; 4];
for c in s.chars() {
match c {
@@ -326,7 +325,7 @@ fn escape_text<W: Write>(s: &str, out: &mut W) -> std::io::Result<()> {
Ok(())
}
-fn escape_attribute<W: Write>(s: &str, out: &mut W) -> std::io::Result<()> {
+fn escape_attribute<W: std::io::Write>(s: &str, out: &mut W) -> std::io::Result<()> {
let mut buf = [0u8; 4];
for c in s.chars() {
match c {