Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.vagga
/target
/Cargo.lock
/.idea
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Next

- Update MSRV to 1.75.0, currently the older of rustc in Ubuntu LTS (Noble Numbat, 1.75.0) and Debian Stable (trixie, 1.85.0)
- Small syntactic tweaks to address all compiler and clippy warnings

# 0.8.0

Current version when changelog started
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ serde_derive = { version = "1.0", optional = true }

[dev-dependencies]
matches = "0.1.2"
itertools = "0.14.0"
11 changes: 4 additions & 7 deletions examples/sync_tcp_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn main() {
process::exit(code);
}

fn resolve(name: &str) -> Result<(), Box<Error>> {
fn resolve(name: &str) -> Result<(), Box<dyn Error>> {
let mut conn = TcpStream::connect("127.0.0.1:53")?;
let mut builder = Builder::new_query(1, true);
builder.add_question(name, false, QueryType::A, QueryClass::IN);
Expand Down Expand Up @@ -62,15 +62,12 @@ fn resolve(name: &str) -> Result<(), Box<Error>> {
if pkt.header.response_code != ResponseCode::NoError {
return Err(pkt.header.response_code.into());
}
if pkt.answers.len() == 0 {
if pkt.answers.is_empty() {
return Err("No records received".into());
}
for ans in pkt.answers {
match ans.data {
RData::A(Record(ip)) => {
println!("{}", ip);
}
_ => {} // ignore
if let RData::A(Record(ip)) = ans.data {
println!("{}", ip);
}
}
Ok(())
Expand Down
11 changes: 4 additions & 7 deletions examples/sync_udp_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn main() {
process::exit(code);
}

fn resolve(name: &str) -> Result<(), Box<Error>> {
fn resolve(name: &str) -> Result<(), Box<dyn Error>> {
let sock = UdpSocket::bind("127.0.0.1:0")?;
sock.connect("127.0.0.1:53")?;
let mut builder = Builder::new_query(1, true);
Expand All @@ -38,15 +38,12 @@ fn resolve(name: &str) -> Result<(), Box<Error>> {
if pkt.header.response_code != ResponseCode::NoError {
return Err(pkt.header.response_code.into());
}
if pkt.answers.len() == 0 {
if pkt.answers.is_empty() {
return Err("No records received".into());
}
for ans in pkt.answers {
match ans.data {
RData::A(Record(ip)) => {
println!("{}", ip);
}
_ => {} // ignore
if let RData::A(Record(ip)) = ans.data {
println!("{}", ip);
}
}
Ok(())
Expand Down
2 changes: 2 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[toolchain]
channel = "1.75.0"
4 changes: 2 additions & 2 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl Builder {
pub fn new_query(id: u16, recursion: bool) -> Builder {
let mut buf = Vec::with_capacity(512);
let head = Header {
id: id,
id,
query: true,
opcode: Opcode::StandardQuery,
authoritative: false,
Expand All @@ -36,7 +36,7 @@ impl Builder {
};
buf.extend([0u8; 12].iter());
head.write(&mut buf[..12]);
Builder { buf: buf }
Builder { buf }
}
/// Adds a question to the packet
///
Expand Down
14 changes: 7 additions & 7 deletions src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ impl From<u16> for Opcode {
}
}
}
impl Into<u16> for Opcode {
fn into(self) -> u16 {
impl From<Opcode> for u16 {
fn from(value: Opcode) -> u16 {
use self::Opcode::*;
match self {
match value {
StandardQuery => 0,
InverseQuery => 1,
ServerStatusRequest => 2,
Expand All @@ -189,15 +189,15 @@ impl From<u8> for ResponseCode {
3 => NameError,
4 => NotImplemented,
5 => Refused,
6...15 => Reserved(code),
6..=15 => Reserved(code),
x => panic!("Invalid response code {}", x),
}
}
}
impl Into<u8> for ResponseCode {
fn into(self) -> u8 {
impl From<ResponseCode> for u8 {
fn from(value: ResponseCode) -> u8 {
use self::ResponseCode::*;
match self {
match value {
NoError => 0,
FormatError => 1,
ServerFailure => 2,
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ extern crate byteorder;
#[cfg(test)] #[macro_use] extern crate matches;
#[macro_use(quick_error)] extern crate quick_error;
#[cfg(feature = "with-serde")] #[macro_use] extern crate serde_derive;
#[cfg(test)] extern crate itertools;

mod enums;
mod structs;
Expand Down
12 changes: 6 additions & 6 deletions src/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl<'a> Name<'a> {
// Set value for return_pos which is the pos in the original
// data buffer that should be used to return after validating
// the offsetted labels.
if let None = return_pos {
if return_pos.is_none() {
return_pos = Some(pos);
}

Expand Down Expand Up @@ -85,9 +85,9 @@ impl<'a> Name<'a> {
byte = parse_data[pos];
}
if let Some(return_pos) = return_pos {
return Ok(Name {labels: &data[..return_pos+2], original: original});
Ok(Name {labels: &data[..return_pos+2], original })
} else {
return Ok(Name {labels: &data[..pos+1], original: original });
Ok(Name {labels: &data[..pos+1], original })
}
}
/// Number of bytes serialized name occupies
Expand All @@ -109,16 +109,16 @@ impl<'a> fmt::Display for Name<'a> {
let off = (BigEndian::read_u16(&data[pos..pos+2])
& !0b1100_0000_0000_0000) as usize;
if pos != 0 {
try!(fmt.write_char('.'));
fmt.write_char('.')?;
}
return fmt::Display::fmt(
&Name::scan(&original[off..], original).unwrap(), fmt)
} else if byte & 0b1100_0000 == 0 {
if pos != 0 {
try!(fmt.write_char('.'));
fmt.write_char('.')?;
}
let end = pos + byte as usize + 1;
try!(fmt.write_str(from_utf8(&data[pos+1..end]).unwrap()));
fmt.write_str(from_utf8(&data[pos + 1..end]).unwrap())?;
pos = end;
continue;
} else {
Expand Down
Loading