Skip to main content

WdlParser

Struct WdlParser 

Source
pub struct WdlParser { /* private fields */ }
Expand description

Parser for WDL (World Distance Lookup) files

The WdlParser provides methods to read and write WDL files, with support for different game versions. It automatically handles the different chunk formats and structures used across World of Warcraft expansions.

§Examples

use std::fs::File;
use std::io::{BufReader, BufWriter};
use wow_wdl::parser::WdlParser;
use wow_wdl::version::WdlVersion;

// Parse a WDL file
let file = File::open("input.wdl").unwrap();
let mut reader = BufReader::new(file);
let parser = WdlParser::new();
let wdl_file = parser.parse(&mut reader).unwrap();

// Write a WDL file
let output = File::create("output.wdl").unwrap();
let mut writer = BufWriter::new(output);
let wotlk_parser = WdlParser::with_version(WdlVersion::Wotlk);
wotlk_parser.write(&mut writer, &wdl_file).unwrap();

Implementations§

Source§

impl WdlParser

Source

pub fn new() -> Self

Creates a new WDL parser with the latest version

This creates a parser configured to work with the most recent WDL format version supported by the library.

§Examples
use wow_wdl::parser::WdlParser;

let parser = WdlParser::new();
Source

pub fn with_version(version: WdlVersion) -> Self

Creates a WDL parser with the specified version

This allows parsing and writing WDL files using a specific game version’s format. This is useful when you know exactly which version you’re working with.

§Examples
use wow_wdl::parser::WdlParser;
use wow_wdl::version::WdlVersion;

let parser = WdlParser::with_version(WdlVersion::Wotlk);
Source

pub fn set_version(&mut self, version: WdlVersion)

Sets the version for the parser

This changes the version used by the parser for future operations.

§Examples
use wow_wdl::parser::WdlParser;
use wow_wdl::version::WdlVersion;

let mut parser = WdlParser::new();
parser.set_version(WdlVersion::Legion);
Source

pub fn version(&self) -> WdlVersion

Gets the current version of the parser

§Examples
use wow_wdl::parser::WdlParser;
use wow_wdl::version::WdlVersion;

let parser = WdlParser::with_version(WdlVersion::Wotlk);
assert_eq!(parser.version(), WdlVersion::Wotlk);
Source

pub fn parse<R: Read + Seek>(&self, reader: &mut R) -> Result<WdlFile>

Parses a WDL file from a reader

This method reads a WDL file from the provided reader and returns a parsed WdlFile structure. It automatically detects the file version and parses all relevant chunks.

§Arguments
  • reader - Any type that implements Read + Seek
§Returns

A Result containing either the parsed WdlFile or an error.

§Examples
use std::fs::File;
use std::io::BufReader;
use wow_wdl::parser::WdlParser;

let file = File::open("input.wdl").unwrap();
let mut reader = BufReader::new(file);
let parser = WdlParser::new();
let wdl_file = parser.parse(&mut reader).unwrap();
Source

pub fn write<W: Write + Seek>( &self, writer: &mut W, file: &WdlFile, ) -> Result<()>

Writes a WDL file to a writer

This method writes a WdlFile structure to the provided writer using the format specified by the parser’s version.

§Arguments
  • writer - Any type that implements Write + Seek
  • file - The WdlFile to write
§Returns

A Result indicating success or an error.

§Examples
use std::fs::File;
use std::io::BufWriter;
use wow_wdl::parser::WdlParser;
use wow_wdl::types::WdlFile;
use wow_wdl::version::WdlVersion;

// Create a new WDL file
let file = WdlFile::with_version(WdlVersion::Wotlk);

// Write the file
let output = File::create("output.wdl").unwrap();
let mut writer = BufWriter::new(output);
let parser = WdlParser::with_version(WdlVersion::Wotlk);
parser.write(&mut writer, &file).unwrap();

Trait Implementations§

Source§

impl Debug for WdlParser

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for WdlParser

Source§

fn default() -> WdlParser

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.