MacTypes_sys/lib.rs
1// Copyright (c) 2016 George Burton
2//
3// Permission is hereby granted, free of charge, to any person obtaining
4// a copy of this software and associated documentation files (the
5// "Software"), to deal in the Software without restriction, including
6// without limitation the rights to use, copy, modify, merge, publish,
7// distribute, sublicense, and/or sell copies of the Software, and to
8// permit persons to whom the Software is furnished to do so, subject to
9// the following conditions:
10//
11// The above copyright notice and this permission notice shall be
12// included in all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
21// Copyright (c) 1985-2008 by Apple Inc.. All rights reserved.
22// @APPLE_LICENSE_HEADER_START@
23//
24// This file contains Original Code and/or Modifications of Original Code
25// as defined in and that are subject to the Apple Public Source License
26// Version 2.0 (the 'License'). You may not use this file except in
27// compliance with the License. Please obtain a copy of the License at
28// http://www.opensource.apple.com/apsl/ and read it before using this
29// file.
30//
31// The Original Code and all software distributed under the License are
32// distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
33// EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
34// INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
35// FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
36// Please see the License for the specific language governing rights and
37// limitations under the License.
38//
39// @APPLE_LICENSE_HEADER_END@
40
41#![allow(non_camel_case_types, non_upper_case_globals, non_snake_case)]
42#![cfg_attr(not(feature = "use_std"), no_std)]
43
44//! The `MacTypes-sys` library provides bindings to the `MacTypes.h` header on MacOS.
45//! This library defines base types used in both Carbon and legacy Cocoa APIs.
46
47extern crate libc;
48
49#[cfg(feature = "use_std")]
50extern crate core;
51
52use core::cmp::{Eq, PartialEq};
53use core::hash::{Hash, Hasher};
54use core::{fmt, mem, ptr, str};
55use libc::*;
56
57/// 8-bit unsigned integer.
58pub type UInt8 = u8;
59/// 8-bit signed integer.
60pub type SInt8 = i8;
61/// 16-bit unsigned integer.
62pub type UInt16 = u16;
63/// 16-bit signed integer.
64pub type SInt16 = i16;
65/// 32-bit unsigned integer.
66pub type UInt32 = u32;
67/// 32-bit signed integer.
68pub type SInt32 = i32;
69
70#[cfg(target_endian = "big")]
71#[repr(C)]
72#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
73pub struct wide {
74 pub hi: SInt32,
75 pub lo: UInt32,
76}
77
78#[cfg(target_endian = "big")]
79#[repr(C)]
80#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
81pub struct UnsignedWide {
82 pub hi: UInt32,
83 pub lo: UInt32,
84}
85
86#[cfg(target_endian = "little")]
87#[repr(C)]
88#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
89pub struct wide {
90 pub lo: UInt32,
91 pub hi: SInt32,
92}
93
94#[cfg(target_endian = "little")]
95#[repr(C)]
96#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
97pub struct UnsignedWide {
98 pub lo: UInt32,
99 pub hi: UInt32,
100}
101
102/// 64-bit signed integer.
103pub type SInt64 = i64;
104/// 64-bit unsigned integer.
105pub type UInt64 = u64;
106
107/// 16-bit signed integer plus 16-bit fraction.
108pub type Fixed = SInt32;
109/// A pointer to a `Fixed`.
110pub type FixedPtr = *mut Fixed;
111/// 2-bit signed integer plus 30-bit fraction.
112pub type Fract = SInt32;
113/// A pointer to a `Fract`.
114pub type FractPtr = *mut Fract;
115/// 16-bit unsigned integer plus 16-bit fraction.
116pub type UnsignedFixed = UInt32;
117/// A pointer to an `UnsignedFixed`.
118pub type UnsignedFixedPtr = *mut UnsignedFixed;
119/// 8-bit signed integer plus 8-bit fraction.
120pub type ShortFixed = SInt16;
121/// A pointer to a `ShortFixed`.
122pub type ShortFixedPtr = *mut ShortFixed;
123
124/// 32 bit IEEE float: 1 sign bit, 8 exponent bits, 23 fraction bits.
125pub type Float32 = f32;
126/// 64 bit IEEE float: 1 sign bit, 11 exponent bits, 52 fraction bits.
127pub type Float64 = f64;
128
129/// 80 bit MacOS float: 1 sign bit, 15 exponent bits, 1 integer bit, 63 fraction bits.
130#[repr(C)]
131#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
132pub struct Float80 {
133 pub exp: SInt16,
134 pub man: [UInt16; 4],
135}
136
137/// 96 bit 68881 float: 1 sign bit, 15 exponent bits, 16 pad bits, 1 integer bit, 63
138/// fraction bits.
139#[repr(C)]
140#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
141pub struct Float96 {
142 pub exp: [SInt16; 2],
143 pub man: [UInt16; 4],
144}
145
146#[repr(C)]
147#[derive(Clone, Copy, Debug, Default, PartialEq)]
148pub struct Float32Point {
149 pub x: Float32,
150 pub y: Float32,
151}
152
153/// Pointer to a non-relocatable block.
154pub type Ptr = *mut c_char;
155/// Pointer to a master pointer to a relocatable block.
156pub type Handle = *mut Ptr;
157/// The number of bytes in a block (signed for historical reasons).
158pub type size = c_long;
159
160/// 16-bit result error code.
161pub type OSErr = SInt16;
162/// 32-bit result error code.
163pub type OSStatus = SInt32;
164/// Address in the clients virtual address space.
165pub type LogicalAddress = *mut c_void;
166/// Address in the clients virtual address space that will only be read.
167pub type ConstLogicalAddress = *const c_void;
168/// Real address as used on the hardware bus.
169pub type PhysicalAddress = *mut c_void;
170/// Pointer to an array of bytes.
171pub type BytePtr = *mut UInt8;
172/// The size of an array of bytes.
173pub type ByteCount = c_ulong;
174/// An offset into an array of bytes.
175pub type ByteOffset = c_ulong;
176/// 32-bit millisecond timer for drivers.
177pub type Duration = SInt32;
178/// 64-bit clock.
179pub type AbsoluteTime = UnsignedWide;
180/// Standard 32-bit set of bit flags.
181pub type OptionBits = UInt32;
182/// 32-bit iteration count.
183pub type ItemCount = c_ulong;
184/// ?
185pub type PBVersion = UInt32;
186/// A particular set of written characters (e.g. Roman vs Cyrillic) and their encoding.
187pub type ScriptCode = SInt16;
188/// A particular language (e.g. English), as represented using a particular ScriptCode.
189pub type LangCode = SInt16;
190/// Designates a language as used in a particular region (e.g. British vs American
191/// English) together with other region-dependent characteristics (e.g. date format).
192pub type RegionCode = SInt16;
193/// A 32-bit value made by packing four 1 byte characters together.
194pub type FourCharCode = UInt32;
195/// A `FourCharCode` used in the OS and file system (e.g. creator).
196pub type OSType = FourCharCode;
197/// A `FourCharCode` used to tag resources (e.g. `DLOG`).
198pub type ResType = FourCharCode;
199/// A pointer to an `OSType`.
200pub type OSTypePtr = *mut OSType;
201/// A pointer to a `ResType`.
202pub type ResTypePtr = *mut ResType;
203
204/// Mac OS historic type, `sizeof(Boolean)==1`.
205pub type Boolean = c_uchar;
206
207/// Generic pointer to a function.
208pub type ProcPtr = unsafe extern "C" fn(c_long);
209/// Pointer to a 68K function that expects parameters in registers.
210pub type Register68kProcPtr = unsafe extern "C" fn();
211
212/// Pointer to classic 68K code or a `RoutineDescriptor`.
213pub type UniversalProcPtr = ProcPtr;
214
215/// Pointer to a `ProcPtr`.
216pub type ProcHandle = *mut ProcPtr;
217/// Pointer to a `UniversalProcPtr`.
218pub type UniversalProcHandle = *mut UniversalProcPtr;
219
220/// # RefCon Types
221///
222/// For access to private data in callbacks, etc.; refcons are generally
223/// used as a pointer to something, but in the 32-bit world refcons in
224/// different APIs have had various types: pointer, unsigned scalar, and
225/// signed scalar. The RefCon types defined here support the current 32-bit
226/// usage but provide normalization to pointer types for 64-bit.
227///
228/// `PRefCon` is preferred for new APIs; `URefCon` and `SRefCon` are primarily
229/// for compatibility with existing APIs.
230pub type PRefCon = *mut c_void;
231
232/// # RefCon Types
233///
234/// For access to private data in callbacks, etc.; refcons are generally
235/// used as a pointer to something, but in the 32-bit world refcons in
236/// different APIs have had various types: pointer, unsigned scalar, and
237/// signed scalar. The RefCon types defined here support the current 32-bit
238/// usage but provide normalization to pointer types for 64-bit.
239///
240/// `PRefCon` is preferred for new APIs; `URefCon` and `SRefCon` are primarily
241/// for compatibility with existing APIs.
242#[cfg(target_pointer_width = "64")]
243pub type URefCon = *mut c_void;
244
245/// # RefCon Types
246///
247/// For access to private data in callbacks, etc.; refcons are generally
248/// used as a pointer to something, but in the 32-bit world refcons in
249/// different APIs have had various types: pointer, unsigned scalar, and
250/// signed scalar. The RefCon types defined here support the current 32-bit
251/// usage but provide normalization to pointer types for 64-bit.
252///
253/// `PRefCon` is preferred for new APIs; `URefCon` and `SRefCon` are primarily
254/// for compatibility with existing APIs.
255#[cfg(target_pointer_width = "64")]
256pub type SRefCon = *mut c_void;
257
258/// # RefCon Types
259///
260/// For access to private data in callbacks, etc.; refcons are generally
261/// used as a pointer to something, but in the 32-bit world refcons in
262/// different APIs have had various types: pointer, unsigned scalar, and
263/// signed scalar. The RefCon types defined here support the current 32-bit
264/// usage but provide normalization to pointer types for 64-bit.
265///
266/// `PRefCon` is preferred for new APIs; `URefCon` and `SRefCon` are primarily
267/// for compatibility with existing APIs.
268#[cfg(target_pointer_width = "32")]
269pub type URefCon = UInt32;
270
271/// # RefCon Types
272///
273/// For access to private data in callbacks, etc.; refcons are generally
274/// used as a pointer to something, but in the 32-bit world refcons in
275/// different APIs have had various types: pointer, unsigned scalar, and
276/// signed scalar. The RefCon types defined here support the current 32-bit
277/// usage but provide normalization to pointer types for 64-bit.
278///
279/// `PRefCon` is preferred for new APIs; `URefCon` and `SRefCon` are primarily
280/// for compatibility with existing APIs.
281#[cfg(target_pointer_width = "32")]
282pub type SRefCon = SInt32;
283
284/// `OSErr`: function performed properly - no error.
285pub const kNoErr: OSErr = 0;
286/// `OptionBits`: all flags false
287pub const kNilOptions: OptionBits = 0;
288/// `KernelID`: `NULL` is for pointers as `kInvalidID` is for ID's
289pub const kInvalidId: u32 = 0;
290/// Array bounds: variable length array
291///
292/// # Note
293///
294/// `kVariableLengthArray` is used in array bounds to specify a variable length array.
295/// It is ususally used in variable length structs when the last field is an array
296/// of any size. Before ANSI C, we used zero as the bounds of variable length
297/// array, but zero length array are illegal in ANSI C.
298///
299/// ## Example usage:
300///
301/// ```c
302/// struct FooList
303/// {
304/// short listLength;
305/// Foo elements[kVariableLengthArray];
306/// };
307/// ```
308pub const kVariableLengthArray: ItemCount = 1;
309/// "????" QuickTime 3.0: default unknown `ResType` or `OSType`
310pub const kUnknownType: OSType = 0x3F3F3F3F;
311
312/// A complete Unicode character in UTF-32 format, with
313/// values from `0` through `0x10FFFF` (excluding the surrogate
314/// range 0xD800-0xDFFF and certain disallowed values).
315pub type UnicodeScalarValue = UInt32;
316/// A complete Unicode character in UTF-32 format, with
317/// values from `0` through `0x10FFFF` (excluding the surrogate
318/// range `0xD800`-`0xDFFF` and certain disallowed values).
319pub type UTF32Char = UInt32;
320/// A 16-bit Unicode code value in the default UTF-16 format.
321/// UnicodeScalarValues `0`-`0xFFFF` are expressed in UTF-16
322/// format using a single `UTF16Char` with the same value.
323/// UnicodeScalarValues `0x10000`-`0x10FFFF` are expressed in
324/// UTF-16 format using a pair of `UTF16Char`s - one in the
325/// high surrogate range (`0xD800`-`0xDBFF`) followed by one in
326/// the low surrogate range (`0xDC00`-`0xDFFF`). All of the
327/// characters defined in Unicode versions through 3.0 are
328/// in the range `0`-`0xFFFF` and can be expressed using a single
329/// `UTF16Char`, thus the term "Unicode character" generally
330/// refers to a `UniChar` = `UTF16Char`.
331pub type UniChar = UInt16;
332/// A 16-bit Unicode code value in the default UTF-16 format.
333/// UnicodeScalarValues `0`-`0xFFFF` are expressed in UTF-16
334/// format using a single `UTF16Char` with the same value.
335/// UnicodeScalarValues `0x10000`-`0x10FFFF` are expressed in
336/// UTF-16 format using a pair of `UTF16Char`s - one in the
337/// high surrogate range (`0xD800`-`0xDBFF`) followed by one in
338/// the low surrogate range (`0xDC00`-`0xDFFF`). All of the
339/// characters defined in Unicode versions through 3.0 are
340/// in the range `0`-`0xFFFF` and can be expressed using a single
341/// `UTF16Char`, thus the term "Unicode character" generally
342/// refers to a `UniChar` = `UTF16Char`.
343pub type UTF16Char = UInt16;
344/// An 8-bit code value in UTF-8 format. `UnicodeScalarValue`s
345/// `0`-`0x7F` are expressed in UTF-8 format using one `UTF8Char`
346/// with the same value. `UnicodeScalarValue`s above `0x7F` are
347/// expressed in UTF-8 format using 2-4 `UTF8Char`s, all with
348/// values in the range `0x80`-`0xF4` (`UnicodeScalarValue`s
349/// `0x100`-`0xFFFF` use two or three `UTF8Char`s,
350/// `UnicodeScalarValue`s `0x10000`-`0x10FFFF` use four `UTF8Chars`).
351pub type UTF8Char = UInt8;
352/// A pointer to an array of `UniChar`s.
353pub type UniCharPtr = *mut UniChar;
354/// A count of UTF-16 code values in an array or buffer.
355pub type UniCharCount = c_ulong;
356/// A pointer to a `UniCharCount`.
357pub type UniCharCountPtr = *mut UniCharCount;
358/// Pascal string holding up to 255 bytes
359pub type Str255 = [c_uchar; 256];
360/// Pascal string holding up to 63 bytes
361pub type Str63 = [c_uchar; 64];
362/// Pascal string holding up to 31 bytes
363pub type Str31 = [c_uchar; 32];
364/// Pascal string holding up to 27 bytes
365pub type Str27 = [c_uchar; 28];
366/// Pascal string holding up to 15 bytes
367pub type Str15 = [c_uchar; 16];
368
369/// The type `Str32` is used in many AppleTalk based data structures.
370/// It holds up to 32 one byte chars. The problem is that with the
371/// length byte it is 33 bytes long. This can cause weird alignment
372/// problems in structures. To fix this the type `Str32Field` has
373/// been created. It should only be used to hold 32 chars, but
374/// it is 34 bytes long so that there are no alignment problems.
375pub type Str32Field = [c_uchar; 34];
376
377/// QuickTime 3.0:
378///
379/// The type `StrFileName` is used to make MacOS structs work
380/// cross-platform. For example `FSSpec` or `SFReply` previously
381/// contained a `Str63` field. They now contain a `StrFileName`
382/// field which is the same when targeting the MacOS but is
383/// a 256 char buffer for Win32 and unix, allowing them to
384/// contain long file names.
385pub type StrFileName = Str63;
386
387/// Pointer to a pascal string.
388pub type StringPtr = *mut c_uchar;
389/// Pointer to a `StringPtr`.
390pub type StringHandle = *mut StringPtr;
391/// Pointer to a read-only pascal string.
392pub type ConstStringPtr = *const c_uchar;
393/// For function parameters only - means string is const.
394pub type ConstStr255Param = *const c_uchar;
395/// For function parameters only - means string is const.
396pub type ConstStr63Param = *const c_uchar;
397/// For function parameters only - means string is const.
398pub type ConstStr31Param = *const c_uchar;
399/// For function parameters only - means string is const.
400pub type ConstStr27Param = *const c_uchar;
401/// For function parameters only - means string is const.
402pub type ConstStr15Param = *const c_uchar;
403/// For function parameters only - means string is const.
404pub type ConstStrFileNameParam = *const ConstStr63Param;
405
406/// Get the length of a pascal string.
407#[inline(always)]
408pub unsafe fn StrLength(string: ConstStr255Param) -> c_uchar {
409 *string
410}
411
412/// Type for unique process identifier.
413#[repr(C)]
414#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
415pub struct ProcessSerialNumber {
416 pub highLongOfPSN: UInt32,
417 pub lowLongOfPSN: UInt32,
418}
419
420pub type ProcessSerialNumberPtr = *mut ProcessSerialNumber;
421
422/// 2D Quickdraw coordinate, range: -32K to +32K.
423#[repr(C)]
424#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
425pub struct Point {
426 pub v: c_short,
427 pub h: c_short,
428}
429
430pub type PointPtr = *mut Point;
431
432/// Rectangular Quickdraw area.
433#[repr(C)]
434#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
435pub struct Rect {
436 pub top: c_short,
437 pub left: c_short,
438 pub bottom: c_short,
439 pub right: c_short,
440}
441
442pub type RectPtr = *mut Rect;
443
444#[repr(C)]
445#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
446pub struct FixedRect {
447 pub top: Fixed,
448 pub left: Fixed,
449 pub bottom: Fixed,
450 pub right: Fixed,
451}
452
453pub type FixedRectPtr = *mut FixedRect;
454
455/// `Char` when used as a parameter (historical 68K convention).
456pub type CharParameter = c_short;
457
458pub const normal: Style = 0;
459pub const bold: Style = 1;
460pub const italic: Style = 2;
461pub const underline: Style = 4;
462pub const outline: Style = 8;
463pub const shadow: Style = 0x10;
464pub const condense: Style = 0x20;
465pub const extend: Style = 0x40;
466
467/// Quickdraw font rendering styles.
468///
469/// # Note
470///
471/// The original Macintosh toolbox in 68K Pascal defined `Style` as a SET.
472/// Both `Style` and `CHAR` occupy 8-bits in packed records or 16-bits when
473/// used as fields in non-packed records or as parameters.
474pub type Style = c_uchar;
475/// `Style` when used as a parameter (historical 68K convention).
476pub type StyleParameter = c_short;
477/// `Style` when used as a field (historical 68K convention).
478pub type StyleField = Style;
479
480/// Count of units.
481pub type TimeValue = SInt32;
482/// Units per second.
483pub type TimeScale = SInt32;
484/// 64-bit count of units (always a struct).
485pub type CompTimeValue = wide;
486/// 64-bit count of units (long long or struct).
487pub type TimeValue64 = SInt64;
488/// An opaque reference to a time base.
489pub type TimeBase = *mut TimeBaseRecord;
490
491#[doc(hidden)]
492#[repr(C)]
493pub struct TimeBaseRecord {
494 _priv: c_void,
495}
496
497/// Package of TimeBase, duration, and scale.
498#[repr(C)]
499#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
500pub struct TimeRecord {
501 /// Units (duration or absolute).
502 pub value: CompTimeValue,
503 /// Units per second.
504 pub scale: TimeScale,
505 /// Reference to the time base
506 pub base: TimeBase,
507}
508
509/// Packed BCD version representation (e.g. "4.2.1a3" is `0x04214003`).
510#[cfg(target_endian = "big")]
511#[repr(C)]
512#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
513pub struct NumVersion {
514 /// 1st part of version number in BCD.
515 pub majorRev: UInt8,
516 /// 2nd & 3rd part of version number share a byte.
517 pub minorAndBugRef: UInt8,
518 /// stage code: dev, alpha, beta, final.
519 pub stage: UInt8,
520 /// revision level of non-released version.
521 pub nonRelRev: UInt8,
522}
523
524/// Packed BCD version representation (e.g. "4.2.1a3" is `0x04214003`).
525#[cfg(target_endian = "little")]
526#[repr(C)]
527#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
528pub struct NumVersion {
529 /// revision level of non-released version.
530 pub nonRelRev: UInt8,
531 /// stage code: dev, alpha, beta, final.
532 pub stage: UInt8,
533 /// 2nd & 3rd part of version number share a byte.
534 pub minorAndBugRef: UInt8,
535 /// 1st part of version number in BCD.
536 pub majorRev: UInt8,
537}
538
539/// Version Release Stage Code.
540pub const developStage: UInt8 = 0x20;
541/// Version Release Stage Code.
542pub const alphaStage: UInt8 = 0x40;
543/// Version Release Stage Code.
544pub const betaStage: UInt8 = 0x60;
545/// Version Release Stage Code.
546pub const finalStage: UInt8 = 0x80;
547
548/// `NumVersionVariant` is a wrapper so `NumVersion` can be accessed as a 32-bit value.
549#[repr(C)]
550#[derive(Clone, Copy)]
551pub union NumVersionVariant {
552 pub parts: NumVersion,
553 pub whole: UInt32,
554}
555
556impl Default for NumVersionVariant {
557 #[inline]
558 fn default() -> Self {
559 NumVersionVariant { whole: 0 }
560 }
561}
562
563impl fmt::Debug for NumVersionVariant {
564 #[inline]
565 fn fmt(&self, fmtr: &mut fmt::Formatter) -> fmt::Result {
566 let parts = unsafe { self.parts };
567 fmtr.debug_struct("NumVersionVariant")
568 .field("parts", &parts)
569 .finish()
570 }
571}
572
573impl PartialEq for NumVersionVariant {
574 #[inline]
575 fn eq(&self, other: &Self) -> bool {
576 unsafe { self.whole.eq(&other.whole) }
577 }
578}
579
580impl PartialEq<NumVersion> for NumVersionVariant {
581 #[inline]
582 fn eq(&self, other: &NumVersion) -> bool {
583 unsafe { self.parts.eq(&other) }
584 }
585}
586
587impl PartialEq<UInt32> for NumVersionVariant {
588 #[inline]
589 fn eq(&self, other: &UInt32) -> bool {
590 unsafe { self.whole.eq(&other) }
591 }
592}
593
594impl Eq for NumVersionVariant {}
595
596impl Hash for NumVersionVariant {
597 #[inline]
598 fn hash<H: Hasher>(&self, state: &mut H) {
599 let whole = unsafe { self.whole };
600 state.write_u32(whole);
601 }
602}
603
604pub type NumVersionVariantPtr = *mut NumVersionVariant;
605pub type NumVersionVariantHandle = *mut NumVersionVariantPtr;
606
607/// Contents of a `vers` resource.
608#[repr(C)]
609pub struct VersRec {
610 pub numericVersion: NumVersion,
611 pub countryCode: c_short,
612 pub shortVersion: Str255,
613 pub reserved: Str255,
614}
615
616// Manual implementation of various traits on `VersRec` as the `Str255` members prevent auto-derive
617
618impl Clone for VersRec {
619 fn clone(&self) -> Self {
620 let mut clone = VersRec::default();
621 clone.numericVersion = self.numericVersion;
622 clone.countryCode = self.countryCode;
623 unsafe {
624 ptr::copy_nonoverlapping(&self.shortVersion, &mut clone.shortVersion, 1);
625 ptr::copy_nonoverlapping(&self.reserved, &mut clone.reserved, 1);
626 }
627 clone
628 }
629}
630
631impl Copy for VersRec {}
632
633impl Default for VersRec {
634 #[inline]
635 fn default() -> Self {
636 VersRec {
637 numericVersion: Default::default(),
638 countryCode: Default::default(),
639 shortVersion: [0; 256],
640 reserved: [0; 256],
641 }
642 }
643}
644
645impl Eq for VersRec {}
646
647impl fmt::Debug for VersRec {
648 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
649 fmt.debug_struct("VersRec")
650 .field("numericVersion", &self.numericVersion)
651 .field("countryCode", &self.countryCode)
652 .field(
653 "shortVersion",
654 &str::from_utf8(&self.shortVersion).map_err(|_| fmt::Error)?,
655 )
656 .field(
657 "reserved",
658 &str::from_utf8(&self.reserved).map_err(|_| fmt::Error)?,
659 )
660 .finish()
661 }
662}
663
664impl Hash for VersRec {
665 fn hash<H: Hasher>(&self, state: &mut H) {
666 self.numericVersion.hash(state);
667 state.write_i16(self.countryCode);
668 state.write(&self.shortVersion);
669 state.write(&self.reserved);
670 }
671}
672
673impl PartialEq for VersRec {
674 fn eq(&self, other: &Self) -> bool {
675 #[inline]
676 fn ptr<T>(slice: &[T]) -> *const c_void {
677 slice.as_ptr() as *const _
678 }
679
680 unsafe {
681 self.numericVersion == other.numericVersion && self.countryCode == other.countryCode &&
682 memcmp(
683 ptr(&self.shortVersion),
684 ptr(&other.shortVersion),
685 mem::size_of::<Str255>(),
686 ) == 0 &&
687 memcmp(
688 ptr(&self.reserved),
689 ptr(&other.reserved),
690 mem::size_of::<Str255>(),
691 ) == 0
692 }
693 }
694}
695
696/// Pointer to a `VersRecPtr`.
697pub type VersRecPtr = *mut VersRec;
698/// Resource Handle containing a `VersRec`.
699pub type VersRecHndl = *mut VersRecPtr;
700
701pub type Byte = UInt8;
702pub type SignedByte = SInt8;
703pub type WidePtr = *mut wide;
704pub type UnsignedWidePtr = *mut UnsignedWide;
705pub type extended80 = Float80;
706pub type extended96 = Float96;
707pub type VHSelect = SInt8;
708
709#[cfg(target_os = "macos")]
710#[cfg_attr(target_os = "macos", link(name = "CoreServices", kind = "framework"))]
711extern "C" {
712 pub fn Debugger();
713 pub fn DebugStr(debuggerMsg: ConstStr255Param);
714 pub fn SysBreak();
715 pub fn SysBreakStr(debuggerMsg: ConstStr255Param);
716 pub fn SysBreakFunc(debuggerMsg: ConstStr255Param);
717}
718
719#[cfg(test)]
720mod versrec_manual_derive_tests {
721 use super::*;
722 #[test]
723 fn test_clone_and_eq() {
724 let mut rec0 = VersRec::default();
725 rec0.countryCode = 14;
726
727 let random_string = b"Hello, world!A)R\xE2Q$";
728 for i in 0..random_string.len() {
729 rec0.shortVersion[i] = random_string[i];
730 }
731
732 let rec1 = rec0.clone();
733 assert_eq!(rec0, rec1);
734 }
735}